KiCad PCB EDA Suite
wizard_add_fplib.cpp File Reference
#include <memory>
#include <wx/wx.h>
#include <wx/uri.h>
#include <wx/dir.h>
#include <wx/progdlg.h>
#include <pgm_base.h>
#include <project.h>
#include <wizard_add_fplib.h>
#include <fp_lib_table.h>
#include <confirm.h>
#include <bitmaps.h>
#include <class_module.h>
#include <env_paths.h>

Go to the source code of this file.

Macros

#define KICAD_FPLIBS_URL_KEY   wxT( "kicad_fplib_url" )
 Wizard for selecting footprint libraries consisting of 4 steps: More...
 
#define KICAD_FPLIBS_LAST_DIR   wxT( "kicad_fplib_last_download_dir" )
 

Functions

static wxString getFilterString ()
 
static OPT< IO_MGR::PCB_FILE_TgetPluginType (const wxString &aPath)
 
static bool passesFilter (const wxString &aFileName, int aFilterIndex)
 

Variables

static const 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 it is a folder or a file. More...
 
   IO_MGR::PCB_FILE_T   m_Plugin
 
fileFilters [FILTER_COUNT]
 

Macro Definition Documentation

#define KICAD_FPLIBS_LAST_DIR   wxT( "kicad_fplib_last_download_dir" )
#define KICAD_FPLIBS_URL_KEY   wxT( "kicad_fplib_url" )

Wizard for selecting footprint libraries consisting of 4 steps:

  • select source (Github/local files)
  • pick libraries
  • present a review of libraries (including validation)
  • select scope (global/project)

Definition at line 56 of file wizard_add_fplib.cpp.

Referenced by WIZARD_FPLIB_TABLE::WIZARD_FPLIB_TABLE(), and WIZARD_FPLIB_TABLE::~WIZARD_FPLIB_TABLE().

Function Documentation

static wxString getFilterString ( )
static

Definition at line 77 of file wizard_add_fplib.cpp.

References fileFilters, FILTER_COUNT, and i.

Referenced by WIZARD_FPLIB_TABLE::WIZARD_FPLIB_TABLE().

78 {
79  wxString filterInit = _( "All supported library formats|" );
80  wxString filter;
81 
82  for( int i = 0; i < FILTER_COUNT; ++i )
83  {
84  // Init part
85  if( i != 0 )
86  filterInit += ";";
87 
88  filterInit += "*." + fileFilters[i].m_Extension;
89 
90  // Rest of the filter string
91  filter += "|" + fileFilters[i].m_Description +
92  "|" + ( fileFilters[i].m_IsFile ? "*." + fileFilters[i].m_Extension : "" );
93  }
94 
95  return filterInit + filter;
96 }
static const int FILTER_COUNT
static const struct @13 fileFilters[FILTER_COUNT]
size_t i
Definition: json11.cpp:597
static OPT<IO_MGR::PCB_FILE_T> getPluginType ( const wxString &  aPath)
static

Definition at line 100 of file wizard_add_fplib.cpp.

References fileFilters, FILTER_COUNT, IO_MGR::GITHUB, i, m_Extension, m_IsFile, and NULLOPT.

Referenced by WIZARD_FPLIB_TABLE::LIBRARY::LIBRARY(), and passesFilter().

101 {
102  if( ( aPath.StartsWith( "http://" ) || aPath.StartsWith( "https://" ) ) )
104 
105  wxFileName path( aPath );
106 
107  for( int i = 0; i < FILTER_COUNT; ++i )
108  {
109  bool ok = false;
110 
111  if( fileFilters[i].m_IsFile )
112  {
113  ok = path.IsFileReadable() && path.GetExt() == fileFilters[i].m_Extension;
114  }
115  else if( path.IsDirReadable() )
116  {
117  // Plugin expects a directory containing files with a specific extension
118  wxDir dir( aPath );
119 
120  if( dir.IsOpened() )
121  {
122  wxString filename;
123 
124  dir.GetFirst( &filename, "*." + fileFilters[i].m_Extension, wxDIR_FILES );
125 
126  ok = !filename.IsEmpty();
127  }
128  }
129 
130  if( ok )
131  return OPT<IO_MGR::PCB_FILE_T>( fileFilters[i].m_Plugin );
132  }
133 
134  return NULLOPT;
135 }
static const int FILTER_COUNT
static const struct @13 fileFilters[FILTER_COUNT]
const auto NULLOPT
Definition: optional.h:9
bool m_IsFile
Whether it is a folder or a file.
size_t i
Definition: json11.cpp:597
boost::optional< T > OPT
Definition: optional.h:7
wxString m_Extension
In case of folders it stands for extensions of files stored inside.
Read only http://github.com repo holding pretty footprints.
Definition: io_mgr.h:59
static bool passesFilter ( const wxString &  aFileName,
int  aFilterIndex 
)
static

Definition at line 139 of file wizard_add_fplib.cpp.

References fileFilters, FILTER_COUNT, getPluginType(), and m_Plugin.

Referenced by WIZARD_FPLIB_TABLE::checkFiles().

140 {
141  wxASSERT( aFilterIndex <= FILTER_COUNT );
142  wxFileName file( aFileName );
143  OPT<IO_MGR::PCB_FILE_T> result = getPluginType( aFileName );
144 
145  if( !result ) // does not match any supported plugin
146  return false;
147 
148  if( aFilterIndex == 0 ) // any plugin will do
149  return true;
150 
151  return ( fileFilters[aFilterIndex - 1].m_Plugin == *result );
152 }
static OPT< IO_MGR::PCB_FILE_T > getPluginType(const wxString &aPath)
static const int FILTER_COUNT
IO_MGR::PCB_FILE_T m_Plugin
static const struct @13 fileFilters[FILTER_COUNT]
boost::optional< T > OPT
Definition: optional.h:7

Variable Documentation

const { ... } fileFilters[FILTER_COUNT]
Initial value:
=
{
{ "KiCad (folder with .kicad_mod files)", "kicad_mod", 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)", "fp", 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(), getFilterString(), getPluginType(), and passesFilter().

const int FILTER_COUNT = 4
static

Definition at line 60 of file wizard_add_fplib.cpp.

Referenced by getFilterString(), getPluginType(), and passesFilter().

wxString m_Description

Description shown in the file picker dialog.

Definition at line 63 of file wizard_add_fplib.cpp.

Referenced by NETCLASS::GetDescription().

wxString m_Extension

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

Definition at line 64 of file wizard_add_fplib.cpp.

Referenced by getPluginType().

bool m_IsFile

Whether it is a folder or a file.

Definition at line 65 of file wizard_add_fplib.cpp.

Referenced by getPluginType().

Definition at line 66 of file wizard_add_fplib.cpp.

Referenced by passesFilter().