KiCad PCB EDA Suite
panel_fp_lib_table.cpp File Reference
#include <set>
#include <wx/regex.h>
#include <wx/grid.h>
#include <fctsys.h>
#include <project.h>
#include <3d_viewer/eda_3d_viewer.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 <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>

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  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, 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 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 244 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 80 of file panel_fp_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 92 of file panel_fp_lib_table.cpp.

93 {
94  /*
95  * TODO(C++20): Clean this up
96  * This is wrapped inside a function to prevent a static initialization order fiasco
97  * with the file extension variables. Once C++20 is allowed in KiCad code, those file
98  * extensions can be made constexpr and this can be removed from a function call and
99  * placed in the file normally.
100  */
101  static const std::map<int, supportedFileType> fileTypes =
102  {
104  {
105  "KiCad (folder with .kicad_mod files)", "", KiCadFootprintFileExtension,
106  false, IO_MGR::KICAD_SEXP
107  }
108  },
110  {
111  "Eagle 6.x (*.lbr)", EagleFootprintLibPathWildcard(), "", true, IO_MGR::EAGLE
112  }
113  },
115  {
116  "KiCad legacy (*.mod)", LegacyFootprintLibPathWildcard(), "", true, IO_MGR::LEGACY
117  }
118  },
120  {
121  "Geda (folder with *.fp files)", "", GedaPcbFootprintLibFileExtension, false,
123  }
124  },
125  };
126 
127  return fileTypes;
128 }
wxString EagleFootprintLibPathWildcard()
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...
const std::string KiCadFootprintFileExtension
wxString LegacyFootprintLibPathWildcard()
Geda PCB file formats.
Definition: io_mgr.h:63
Legacy Pcbnew file formats prior to s-expression.
Definition: io_mgr.h:56
const std::string GedaPcbFootprintLibFileExtension
S-expression Pcbnew file format.
Definition: io_mgr.h:57

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 1023 of file panel_fp_lib_table.cpp.

1024 {
1025  FP_LIB_TABLE* globalTable = &GFootprintTable;
1026  wxString globalTablePath = FP_LIB_TABLE::GetGlobalTableFileName();
1027  FP_LIB_TABLE* projectTable = aKiway->Prj().PcbFootprintLibs();
1028  wxString projectTablePath = aKiway->Prj().FootprintLibTblName();
1029  wxString msg;
1030 
1031  DIALOG_EDIT_LIBRARY_TABLES dlg( aCaller, _( "Footprint Libraries" ) );
1032  dlg.SetKiway( &dlg, aKiway );
1033 
1034  if( aKiway->Prj().IsNullProject() )
1035  projectTable = nullptr;
1036 
1037  dlg.InstallPanel( new PANEL_FP_LIB_TABLE( &dlg, globalTable, globalTablePath,
1038  projectTable, projectTablePath,
1039  aKiway->Prj().GetProjectPath() ) );
1040 
1041  if( dlg.ShowModal() == wxID_CANCEL )
1042  return;
1043 
1044  if( dlg.m_GlobalTableChanged )
1045  {
1046  try
1047  {
1048  globalTable->Save( globalTablePath );
1049  }
1050  catch( const IO_ERROR& ioe )
1051  {
1052  msg.Printf( _( "Error saving global library table:\n\n%s" ), ioe.What() );
1053  wxMessageBox( msg, _( "File Save Error" ), wxOK | wxICON_ERROR );
1054  }
1055  }
1056 
1057  if( projectTable && dlg.m_ProjectTableChanged )
1058  {
1059  try
1060  {
1061  projectTable->Save( projectTablePath );
1062  }
1063  catch( const IO_ERROR& ioe )
1064  {
1065  msg.Printf( _( "Error saving project-specific library table:\n\n%s" ), ioe.What() );
1066  wxMessageBox( msg, _( "File Save Error" ), wxOK | wxICON_ERROR );
1067  }
1068  }
1069 
1070  auto editor = (FOOTPRINT_EDIT_FRAME*) aKiway->Player( FRAME_FOOTPRINT_EDITOR, false );
1071 
1072  if( editor )
1073  editor->SyncLibraryTree( true );
1074 
1075  auto viewer = (FOOTPRINT_VIEWER_FRAME*) aKiway->Player( FRAME_FOOTPRINT_VIEWER, false );
1076 
1077  if( viewer )
1078  viewer->ReCreateLibraryList();
1079 }
VTBL_ENTRY PROJECT & Prj() const
Function Prj returns the PROJECT associated with this KIWAY.
Definition: kiway.cpp:172
FP_LIB_TABLE GFootprintTable
!!!!!!!!!!!!!! This code is obsolete because of the merge into pcbnew, don't bother with it.
Component library viewer main window.
VTBL_ENTRY const wxString GetProjectPath() const
Function GetProjectPath returns the full path of the project.
Definition: project.cpp:123
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:342
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:29
VTBL_ENTRY bool IsNullProject() const
Checks if this project is a null project (i.e.
Definition: project.cpp:135
VTBL_ENTRY FP_LIB_TABLE * PcbFootprintLibs(KIWAY &aKiway)
Return the table of footprint libraries.
Definition: project.cpp:291
#define _(s)
Definition: 3d_actions.cpp:33
void Save(const wxString &aFileName) const
Write this library table to aFileName in s-expression form.
Dialog to show and edit symbol library tables.
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
VTBL_ENTRY const wxString FootprintLibTblName() const
Function FootprintLibTblName returns the path and filename of this project's fp-lib-table,...
Definition: project.cpp:147
static wxString GetGlobalTableFileName()
Function GetGlobalTableFileName.

References _, 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().