KiCad PCB EDA Suite
WIZARD_FPLIB_TABLE::LIBRARY Class Reference

#include <wizard_add_fplib.h>

Public Types

enum  STATUS { OK, INVALID, NOT_CHECKED }
 

Possible states of validation.

More...
 

Public Member Functions

 LIBRARY (const wxString &aPath, const wxString &aDescription=wxEmptyString)
 
 ~LIBRARY ()
 
bool Test ()
 Function Test Uses the associated plugin to validate the library contents. More...
 
boost::optional< IO_MGR::PCB_FILE_TGetPluginType () const
 Function GetPluginType Returns the plugin type, autodetected basing on the path. More...
 
wxString GetPluginName () const
 Function GetPluginName Returns the plugin name, as used in the FPLIB table editor. More...
 
const wxString & GetAbsolutePath () const
 Function GetAbsolutePath Returns the absolute path for the library. More...
 
wxString GetRelativePath (const wxString &aBase, const wxString &aSubstitution=wxEmptyString) const
 Function GetRelativePath Returns the relative path, based on the input path with the base part replaced. More...
 
wxString GetAutoPath (LIB_SCOPE aScope) const
 Function GetAutoPath Returns path that is either absolute or related to KISYSMOD/KIPRJMOD if the files are stored within one of the mentioned paths. More...
 
wxString GetDescription () const
 Function GetDescription Returns the description for the library. More...
 
STATUS GetStatus () const
 Function GetStatus Returns the validity status for the library. More...
 

Protected Member Functions

void setPath (const wxString &aPath)
 
void setPluginType (IO_MGR::PCB_FILE_T aType)
 
wxString replaceEnv (const wxString &aEnvVar, bool aFilePath=true) const
 Function replaceEnv replaces path with environmental variable if applicable. More...
 

Protected Attributes

wxString m_path
 
wxString m_description
 
boost::optional< IO_MGR::PCB_FILE_Tm_plugin
 
STATUS m_status
 

Friends

class WIZARD_FPLIB_TABLE
 

Detailed Description

Definition at line 97 of file wizard_add_fplib.h.

Member Enumeration Documentation

Constructor & Destructor Documentation

WIZARD_FPLIB_TABLE::LIBRARY::LIBRARY ( const wxString &  aPath,
const wxString &  aDescription = wxEmptyString 
)

Definition at line 154 of file wizard_add_fplib.cpp.

References getPluginType(), and m_plugin.

154  :
155  m_path( aPath ), m_description( aDescription ), m_status( NOT_CHECKED )
156 {
157  m_plugin = getPluginType( aPath );
158 }
boost::optional< IO_MGR::PCB_FILE_T > m_plugin
static boost::optional< IO_MGR::PCB_FILE_T > getPluginType(const wxString &aPath)
WIZARD_FPLIB_TABLE::LIBRARY::~LIBRARY ( )
inline

Definition at line 101 of file wizard_add_fplib.h.

102  {
103  }

Member Function Documentation

const wxString& WIZARD_FPLIB_TABLE::LIBRARY::GetAbsolutePath ( ) const
inline

Function GetAbsolutePath Returns the absolute path for the library.

Definition at line 135 of file wizard_add_fplib.h.

References m_path.

136  {
137  return m_path;
138  }
wxString WIZARD_FPLIB_TABLE::LIBRARY::GetAutoPath ( LIB_SCOPE  aScope) const

Function GetAutoPath Returns path that is either absolute or related to KISYSMOD/KIPRJMOD if the files are stored within one of the mentioned paths.

Parameters
aScoepis the scope for the library. It determines the environmental variables that are used to check the path (GLOBAL scope checks only KISYSMOD, while PROJECT scope checks both KISYSMOD & KIPRJMOD).

Definition at line 249 of file wizard_add_fplib.cpp.

References FP_LIB_TABLE::GlobalPathEnvVariableName(), and PROJECT_VAR_NAME.

250 {
251  const wxString& global_env = FP_LIB_TABLE::GlobalPathEnvVariableName();
252  const wxString& project_env = PROJECT_VAR_NAME;
253  const wxString& github_env( "KIGITHUB" );
254 
255  wxString rel_path;
256 
257  // KISYSMOD check
258  rel_path = replaceEnv( global_env );
259 
260  if( !rel_path.IsEmpty() )
261  return rel_path;
262 
263  // KIGITHUB check
264  rel_path = replaceEnv( github_env, false );
265 
266  if( !rel_path.IsEmpty() )
267  return rel_path;
268 
269  // KIPRJMOD check
270  if( aScope == PROJECT )
271  {
272  rel_path = replaceEnv( project_env );
273 
274  if( !rel_path.IsEmpty() )
275  return rel_path;
276  }
277 
278  // Return the full path
279  return m_path;
280 }
Class PROJECT holds project specific data.
Definition: project.h:52
#define PROJECT_VAR_NAME
A variable name whose value holds the current project directory.
Definition: project.h:32
static const wxString GlobalPathEnvVariableName()
Function GlobalPathEnvVarVariableName.
wxString replaceEnv(const wxString &aEnvVar, bool aFilePath=true) const
Function replaceEnv replaces path with environmental variable if applicable.
wxString WIZARD_FPLIB_TABLE::LIBRARY::GetDescription ( ) const

Function GetDescription Returns the description for the library.

If it is not specified in the constructor, it is just the filename.

Definition at line 283 of file wizard_add_fplib.cpp.

284 {
285  if( !m_description.IsEmpty() )
286  return m_description;
287 
288  wxFileName filename( m_path );
289  return filename.GetName();
290 }
wxString WIZARD_FPLIB_TABLE::LIBRARY::GetPluginName ( ) const

Function GetPluginName Returns the plugin name, as used in the FPLIB table editor.

Definition at line 199 of file wizard_add_fplib.cpp.

References IO_MGR::EAGLE, IO_MGR::GEDA_PCB, IO_MGR::GITHUB, IO_MGR::KICAD, and IO_MGR::LEGACY.

200 {
201  if( !m_plugin )
202  return _( "UNKNOWN" );
203 
204  switch( *m_plugin )
205  {
206  case IO_MGR::LEGACY:
207  return wxT( "Legacy" );
208 
209  case IO_MGR::KICAD:
210  return wxT( "KiCad" );
211 
212  case IO_MGR::EAGLE:
213  return wxT( "Eagle" );
214 
215  case IO_MGR::GEDA_PCB:
216  return wxT( "Geda-PCB" );
217 
218  case IO_MGR::GITHUB:
219  return wxT( "Github" );
220 
221  default:
222  return _( "UNKNOWN" );
223  }
224 
225  /*PLUGIN* p = IO_MGR::PluginFind( *m_plugin );
226 
227  if( !p )
228  return _( "UNKNOWN" );
229 
230  return p->PluginName();*/
231 }
boost::optional< IO_MGR::PCB_FILE_T > m_plugin
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
Read only http://github.com repo holding pretty footprints.
Definition: io_mgr.h:58
boost::optional<IO_MGR::PCB_FILE_T> WIZARD_FPLIB_TABLE::LIBRARY::GetPluginType ( ) const
inline

Function GetPluginType Returns the plugin type, autodetected basing on the path.

Returns
Returns empty boost::optional if the type could not be autodetected.

Definition at line 120 of file wizard_add_fplib.h.

References m_plugin.

121  {
122  return m_plugin;
123  }
boost::optional< IO_MGR::PCB_FILE_T > m_plugin
wxString WIZARD_FPLIB_TABLE::LIBRARY::GetRelativePath ( const wxString &  aBase,
const wxString &  aSubstitution = wxEmptyString 
) const

Function GetRelativePath Returns the relative path, based on the input path with the base part replaced.

Parameters
aBaseis the base for the relative path.
aSubstitutionis the string to be replace the base path.
Returns
Adjusted path if possible, or the absolute path when it is not possible.

Definition at line 234 of file wizard_add_fplib.cpp.

235 {
236  wxFileName libPath( m_path );
237 
238  // Check if the library path belongs to the project folder
239  if( libPath.MakeRelativeTo( aBase ) && !libPath.GetFullPath().StartsWith( ".." ) )
240  {
241  return wxString( aSubstitution + "/" + libPath.GetFullPath() );
242  }
243 
244  // Probably on another drive, so the relative path will not work
245  return wxEmptyString;
246 }
STATUS WIZARD_FPLIB_TABLE::LIBRARY::GetStatus ( ) const
inline

Function GetStatus Returns the validity status for the library.

It requires running Test() before, to get a result different than NOT_CHECKED.

Definition at line 171 of file wizard_add_fplib.h.

References m_status.

172  {
173  return m_status;
174  }
wxString WIZARD_FPLIB_TABLE::LIBRARY::replaceEnv ( const wxString &  aEnvVar,
bool  aFilePath = true 
) const
protected

Function replaceEnv replaces path with environmental variable if applicable.

Parameters
aEnvVaris the environmental variable that should be substituted.
aFilePathdetermines if the path is a file path (contrary to e.g. http address).

Definition at line 293 of file wizard_add_fplib.cpp.

294 {
295  wxString env_path;
296 
297  if( !wxGetEnv( aEnvVar, &env_path ) )
298  return wxEmptyString;
299 
300  //return GetRelativePath( m_path, wxString( "$(" + aEnvVar + ")" ) );
301 
302  wxString result( m_path );
303 
304  if( result.Replace( env_path, wxString( "$(" + aEnvVar + ")" ) ) )
305  return result;
306 
307  return wxEmptyString;
308 }
void WIZARD_FPLIB_TABLE::LIBRARY::setPath ( const wxString &  aPath)
inlineprotected

Definition at line 177 of file wizard_add_fplib.h.

References m_path.

178  {
179  m_path = aPath;
180  }
void WIZARD_FPLIB_TABLE::LIBRARY::setPluginType ( IO_MGR::PCB_FILE_T  aType)
inlineprotected

Definition at line 182 of file wizard_add_fplib.h.

References m_plugin.

183  {
184  m_plugin = aType;
185  }
boost::optional< IO_MGR::PCB_FILE_T > m_plugin
bool WIZARD_FPLIB_TABLE::LIBRARY::Test ( )

Function Test Uses the associated plugin to validate the library contents.

Returns
True if the library and the matched plugin type are valid.

Definition at line 161 of file wizard_add_fplib.cpp.

References PLUGIN::FootprintEnumerate(), INVALID, OK, and IO_MGR::PluginFind().

162 {
163  if( !m_plugin )
164  {
166  return false;
167  }
168 
170  wxArrayString footprints;
171 
172  if( !p )
173  {
175  return false;
176  }
177 
178  try
179  {
180  footprints = p->FootprintEnumerate( m_path );
181  }
182  catch( IO_ERROR& )
183  {
185  return false;
186  }
187 
188  if( footprints.GetCount() == 0 )
189  {
191  return false;
192  }
193 
195  return true;
196 }
boost::optional< IO_MGR::PCB_FILE_T > m_plugin
virtual wxArrayString FootprintEnumerate(const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL)
Function FootprintEnumerate returns a list of footprint names contained within the library at aLibrar...
Definition: plugin.cpp:61
static PLUGIN * PluginFind(PCB_FILE_T aFileType)
Function PluginFind returns a PLUGIN which the caller can use to import, export, save, or load design documents.
Definition: io_mgr.cpp:58
Class PLUGIN is a base class that BOARD loading and saving plugins should derive from.
Definition: io_mgr.h:193
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:47

Friends And Related Function Documentation

friend class WIZARD_FPLIB_TABLE
friend

Definition at line 200 of file wizard_add_fplib.h.

Member Data Documentation

wxString WIZARD_FPLIB_TABLE::LIBRARY::m_description
protected

Definition at line 196 of file wizard_add_fplib.h.

wxString WIZARD_FPLIB_TABLE::LIBRARY::m_path
protected

Definition at line 195 of file wizard_add_fplib.h.

Referenced by GetAbsolutePath(), and setPath().

boost::optional<IO_MGR::PCB_FILE_T> WIZARD_FPLIB_TABLE::LIBRARY::m_plugin
protected

Definition at line 197 of file wizard_add_fplib.h.

Referenced by GetPluginType(), LIBRARY(), and setPluginType().

STATUS WIZARD_FPLIB_TABLE::LIBRARY::m_status
protected

Definition at line 198 of file wizard_add_fplib.h.

Referenced by GetStatus().


The documentation for this class was generated from the following files: