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.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_file_dir_picker.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>

Go to the source code of this file.

Classes

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
 

Functions

static wxString getFilterString ()
 
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...
 

Variables

static constexpr int FILTER_COUNT = 4
 
struct {
   wxString   m_Description
 Description shown in the file picker dialog. More...
 
   wxString   m_Extension
 In case of folders it stands for extensions of files stored inside. More...
 
   bool   m_IsFile
 Whether the library is a folder or a file. More...
 
   IO_MGR::PCB_FILE_T   m_Plugin
 
fileFilters [FILTER_COUNT]
 

Macro Definition Documentation

#define MYID_OPTIONS_EDITOR   15151

Function Documentation

static wxString getFilterString ( )
static

Definition at line 81 of file panel_fp_lib_table.cpp.

References fileFilters, FILTER_COUNT, i, m_Extension, and m_IsFile.

Referenced by PANEL_FP_LIB_TABLE::browseLibrariesHandler().

82 {
83  wxString filterAll = _( "All supported library formats|" );
84  bool firstFilterAll = true;
85  wxString filter;
86 
87  for( int i = 0; i < FILTER_COUNT; ++i )
88  {
89  if( fileFilters[i].m_IsFile )
90  {
91  // "All supported formats" filter
92  if( firstFilterAll )
93  firstFilterAll = false;
94  else
95  filterAll += ";";
96 
97  wxASSERT( !fileFilters[i].m_Extension.IsEmpty() );
98  filterAll += "*." + fileFilters[i].m_Extension;
99  }
100 
101 
102  // Individual filter strings
103  filter += "|" + fileFilters[i].m_Description +
104  "|" + ( fileFilters[i].m_IsFile ? "*." + fileFilters[i].m_Extension : "" );
105  }
106 
107  return filterAll + filter;
108 }
static constexpr int FILTER_COUNT
wxString m_Extension
In case of folders it stands for extensions of files stored inside.
size_t i
Definition: json11.cpp:597
bool m_IsFile
Whether the library is a folder or a file.
static const struct @9 fileFilters[FILTER_COUNT]
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 800 of file panel_fp_lib_table.cpp.

References PROJECT::FootprintLibTblName(), FRAME_PCB_MODULE_EDITOR, FRAME_PCB_MODULE_VIEWER, FP_LIB_TABLE::GetGlobalTableFileName(), PROJECT::GetProjectPath(), GFootprintTable, DIALOG_EDIT_LIBRARY_TABLES::InstallPanel(), DIALOG_EDIT_LIBRARY_TABLES::m_GlobalTableChanged, DIALOG_EDIT_LIBRARY_TABLES::m_ProjectTableChanged, PANEL_FP_LIB_TABLE::PANEL_FP_LIB_TABLE(), PROJECT::PcbFootprintLibs(), KIWAY::Player(), KIWAY::Prj(), LIB_TABLE::Save(), KIWAY_HOLDER::SetKiway(), and IO_ERROR::What().

Referenced by PCB::IFACE::CreateWindow(), PCB_EDIT_FRAME::Process_Config(), and FOOTPRINT_EDIT_FRAME::ProcessPreferences().

801 {
802  FP_LIB_TABLE* globalTable = &GFootprintTable;
803  wxString globalTablePath = FP_LIB_TABLE::GetGlobalTableFileName();
804  FP_LIB_TABLE* projectTable = aKiway->Prj().PcbFootprintLibs();
805  wxString projectTablePath = aKiway->Prj().FootprintLibTblName();
806  wxString msg;
807 
808  DIALOG_EDIT_LIBRARY_TABLES dlg( aCaller, _( "Footprint Libraries" ) );
809  dlg.SetKiway( &dlg, aKiway );
810 
811  dlg.InstallPanel( new PANEL_FP_LIB_TABLE( &dlg, globalTable, globalTablePath,
812  projectTable, projectTablePath,
813  aKiway->Prj().GetProjectPath() ) );
814 
815  if( dlg.ShowModal() == wxID_CANCEL )
816  return;
817 
818  if( dlg.m_GlobalTableChanged )
819  {
820  try
821  {
822  globalTable->Save( globalTablePath );
823  }
824  catch( const IO_ERROR& ioe )
825  {
826  msg.Printf( _( "Error saving global library table:\n\n%s" ), ioe.What() );
827  wxMessageBox( msg, _( "File Save Error" ), wxOK | wxICON_ERROR );
828  }
829  }
830 
831  if( dlg.m_ProjectTableChanged )
832  {
833  try
834  {
835  projectTable->Save( projectTablePath );
836  }
837  catch( const IO_ERROR& ioe )
838  {
839  msg.Printf( _( "Error saving project-specific library table:\n\n%s" ), ioe.What() );
840  wxMessageBox( msg, _( "File Save Error" ), wxOK | wxICON_ERROR );
841  }
842  }
843 
844  auto editor = (FOOTPRINT_EDIT_FRAME*) aKiway->Player( FRAME_PCB_MODULE_EDITOR, false );
845 
846  if( editor )
847  editor->SyncLibraryTree( true );
848 
849  auto viewer = (FOOTPRINT_VIEWER_FRAME*) aKiway->Player( FRAME_PCB_MODULE_VIEWER, false );
850 
851  if( viewer )
852  viewer->ReCreateLibraryList();
853 }
Component library viewer main window.
FP_LIB_TABLE GFootprintTable
The global footprint library table.
Definition: pcbnew.cpp:333
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:300
VTBL_ENTRY PROJECT & Prj() const
Function Prj returns the PROJECT associated with this KIWAY.
Definition: kiway.cpp:142
void Save(const wxString &aFileName) const
Write this library table to aFileName in s-expression form.
VTBL_ENTRY const wxString FootprintLibTblName() const
Function FootprintLibTblName returns the path and filename of this project&#39;s fp-lib-table, i.e.
Definition: project.cpp:120
VTBL_ENTRY FP_LIB_TABLE * PcbFootprintLibs(KIWAY &aKiway)
Return the table of footprint libraries.
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:33
VTBL_ENTRY const wxString GetProjectPath() const
Function GetProjectPath returns the full path of the project.
Definition: project.cpp:102
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
static wxString GetGlobalTableFileName()
Function GetGlobalTableFileName.

Variable Documentation

const { ... } fileFilters[FILTER_COUNT]
Initial value:
=
{
{ "KiCad (folder with .kicad_mod files)", "", false, IO_MGR::KICAD_SEXP },
{ "Eagle 6.x (*.lbr)", "lbr", true, IO_MGR::EAGLE },
{ "KiCad legacy (*.mod)", "mod", true, IO_MGR::LEGACY },
{ "Geda (folder with *.fp files)", "", false, IO_MGR::GEDA_PCB },
}
Geda PCB file formats.
Definition: io_mgr.h:58
Legacy Pcbnew file formats prior to s-expression.
Definition: io_mgr.h:54
S-expression Pcbnew file format.
Definition: io_mgr.h:55

Referenced by AskLoadBoardFileName(), and getFilterString().

constexpr int FILTER_COUNT = 4
static

Definition at line 63 of file panel_fp_lib_table.cpp.

Referenced by getFilterString().

wxString m_Description

Description shown in the file picker dialog.

Definition at line 66 of file panel_fp_lib_table.cpp.

Referenced by NETCLASS::GetDescription().

wxString m_Extension

In case of folders it stands for extensions of files stored inside.

Definition at line 67 of file panel_fp_lib_table.cpp.

Referenced by getFilterString().

bool m_IsFile

Whether the library is a folder or a file.

Definition at line 68 of file panel_fp_lib_table.cpp.

Referenced by getFilterString().

Definition at line 69 of file panel_fp_lib_table.cpp.