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>
#include <widgets/grid_text_button_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 82 of file panel_fp_lib_table.cpp.

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

Referenced by PANEL_FP_LIB_TABLE::browseLibrariesHandler().

83 {
84  wxString filterAll = _( "All supported library formats|" );
85  bool firstFilterAll = true;
86  wxString filter;
87 
88  for( int i = 0; i < FILTER_COUNT; ++i )
89  {
90  if( fileFilters[i].m_IsFile )
91  {
92  // "All supported formats" filter
93  if( firstFilterAll )
94  firstFilterAll = false;
95  else
96  filterAll += ";";
97 
98  wxASSERT( !fileFilters[i].m_Extension.IsEmpty() );
99  filterAll += "*." + fileFilters[i].m_Extension;
100  }
101 
102 
103  // Individual filter strings
104  filter += "|" + fileFilters[i].m_Description +
105  "|" + ( fileFilters[i].m_IsFile ? "*." + fileFilters[i].m_Extension : "" );
106  }
107 
108  return filterAll + filter;
109 }
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 805 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().

806 {
807  FP_LIB_TABLE* globalTable = &GFootprintTable;
808  wxString globalTablePath = FP_LIB_TABLE::GetGlobalTableFileName();
809  FP_LIB_TABLE* projectTable = aKiway->Prj().PcbFootprintLibs();
810  wxString projectTablePath = aKiway->Prj().FootprintLibTblName();
811  wxString msg;
812 
813  DIALOG_EDIT_LIBRARY_TABLES dlg( aCaller, _( "Footprint Libraries" ) );
814  dlg.SetKiway( &dlg, aKiway );
815 
816  dlg.InstallPanel( new PANEL_FP_LIB_TABLE( &dlg, globalTable, globalTablePath,
817  projectTable, projectTablePath,
818  aKiway->Prj().GetProjectPath() ) );
819 
820  if( dlg.ShowModal() == wxID_CANCEL )
821  return;
822 
823  if( dlg.m_GlobalTableChanged )
824  {
825  try
826  {
827  globalTable->Save( globalTablePath );
828  }
829  catch( const IO_ERROR& ioe )
830  {
831  msg.Printf( _( "Error saving global library table:\n\n%s" ), ioe.What() );
832  wxMessageBox( msg, _( "File Save Error" ), wxOK | wxICON_ERROR );
833  }
834  }
835 
836  if( dlg.m_ProjectTableChanged )
837  {
838  try
839  {
840  projectTable->Save( projectTablePath );
841  }
842  catch( const IO_ERROR& ioe )
843  {
844  msg.Printf( _( "Error saving project-specific library table:\n\n%s" ), ioe.What() );
845  wxMessageBox( msg, _( "File Save Error" ), wxOK | wxICON_ERROR );
846  }
847  }
848 
849  auto editor = (FOOTPRINT_EDIT_FRAME*) aKiway->Player( FRAME_PCB_MODULE_EDITOR, false );
850 
851  if( editor )
852  editor->SyncLibraryTree( true );
853 
854  auto viewer = (FOOTPRINT_VIEWER_FRAME*) aKiway->Player( FRAME_PCB_MODULE_VIEWER, false );
855 
856  if( viewer )
857  viewer->ReCreateLibraryList();
858 }
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 64 of file panel_fp_lib_table.cpp.

Referenced by getFilterString().

wxString m_Description

Description shown in the file picker dialog.

Definition at line 67 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 68 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 69 of file panel_fp_lib_table.cpp.

Referenced by getFilterString().

Definition at line 70 of file panel_fp_lib_table.cpp.