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

◆ MYID_OPTIONS_EDITOR

#define MYID_OPTIONS_EDITOR   15151

Definition at line 153 of file panel_fp_lib_table.cpp.

Function Documentation

◆ getFilterString()

static wxString getFilterString ( )
static

Definition at line 82 of file panel_fp_lib_table.cpp.

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]

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

Referenced by PANEL_FP_LIB_TABLE::browseLibrariesHandler().

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

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

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

Variable Documentation

◆ fileFilters

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:60
Legacy Pcbnew file formats prior to s-expression.
Definition: io_mgr.h:56
S-expression Pcbnew file format.
Definition: io_mgr.h:57

Referenced by AskLoadBoardFileName(), and getFilterString().

◆ FILTER_COUNT

constexpr int FILTER_COUNT = 4
static

Definition at line 64 of file panel_fp_lib_table.cpp.

Referenced by getFilterString().

◆ m_Description

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(), and NETCLASS::SetDescription().

◆ m_Extension

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().

◆ m_IsFile

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().

◆ m_Plugin

Definition at line 70 of file panel_fp_lib_table.cpp.