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>

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_DOWNLOAD_DIR   wxT( "kicad_fplib_last_download_dir" )
 

Functions

static wxString getFilterString ()
 
static boost::optional< 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_DOWNLOAD_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 55 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 76 of file wizard_add_fplib.cpp.

References fileFilters, and FILTER_COUNT.

Referenced by WIZARD_FPLIB_TABLE::WIZARD_FPLIB_TABLE().

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

Definition at line 99 of file wizard_add_fplib.cpp.

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

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

100 {
101  if( ( aPath.StartsWith( "http://" ) || aPath.StartsWith( "https://" ) ) )
103 
104  wxFileName path( aPath );
105 
106  for( int i = 0; i < FILTER_COUNT; ++i )
107  {
108  bool ok = false;
109 
110  if( fileFilters[i].m_IsFile )
111  {
112  ok = path.IsFileReadable() && path.GetExt() == fileFilters[i].m_Extension;
113  }
114  else if( path.IsDirReadable() )
115  {
116  // Plugin expects a directory containing files with a specific extension
117  wxDir dir( aPath );
118 
119  if( dir.IsOpened() )
120  {
121  wxString filename;
122 
123  dir.GetFirst( &filename, "*." + fileFilters[i].m_Extension, wxDIR_FILES );
124 
125  ok = !filename.IsEmpty();
126  }
127  }
128 
129  if( ok )
130  return boost::optional<IO_MGR::PCB_FILE_T>( fileFilters[i].m_Plugin );
131  }
132 
133  return boost::none;
134 }
static const int FILTER_COUNT
bool m_IsFile
Whether it is a folder or a file.
static const struct @16 fileFilters[FILTER_COUNT]
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:58
static bool passesFilter ( const wxString &  aFileName,
int  aFilterIndex 
)
static

Definition at line 138 of file wizard_add_fplib.cpp.

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

Referenced by WIZARD_FPLIB_TABLE::checkFiles().

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

Variable Documentation

const { ... } fileFilters[FILTER_COUNT]
Initial value:
=
{
{ "KiCad (folder with .kicad_mod files)", "kicad_mod", false, IO_MGR::KICAD },
{ "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:57
S-expression Pcbnew file format.
Definition: io_mgr.h:54
Legacy Pcbnew file formats prior to s-expression.
Definition: io_mgr.h:53

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

const int FILTER_COUNT = 4
static

Definition at line 59 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 62 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 63 of file wizard_add_fplib.cpp.

Referenced by getPluginType().

bool m_IsFile

Whether it is a folder or a file.

Definition at line 64 of file wizard_add_fplib.cpp.

Referenced by getPluginType().

Definition at line 65 of file wizard_add_fplib.cpp.

Referenced by passesFilter().