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...
 
OPT< 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
 
OPT< 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 155 of file wizard_add_fplib.cpp.

References getPluginType(), and m_plugin.

155  :
156  m_path( aPath ), m_description( aDescription ), m_status( NOT_CHECKED )
157 {
158  m_plugin = getPluginType( aPath );
159 }
static OPT< IO_MGR::PCB_FILE_T > getPluginType(const wxString &aPath)
OPT< IO_MGR::PCB_FILE_T > m_plugin
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 GetAutoPath(), GetDescription(), GetRelativePath(), and 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
aScopeis 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 224 of file wizard_add_fplib.cpp.

References m_path, NormalizePath(), Pgm(), PROJECT_VAR_NAME, and replaceEnv().

Referenced by GetAbsolutePath().

225 {
226  const wxString& project_env = PROJECT_VAR_NAME;
227  const wxString& github_env( "KIGITHUB" );
228 
229  wxString rel_path;
230 
231  // The extra KIGITHUB and KIPRJCHECKS are still here since Pgm.GetLocalVariables() does not
232  // contain the KIPRJMOD env var, and the KIGITHUB does not pass the IsAbsolutePath check
233  // that happens in NormalizePath(...) since it starts with https://
234 
235  // KIGITHUB check
236  rel_path = replaceEnv( github_env, false );
237 
238  if( !rel_path.IsEmpty() )
239  return rel_path;
240 
241  // KIPRJMOD check
242  if( aScope == PROJECT )
243  {
244  rel_path = replaceEnv( project_env );
245 
246  if( !rel_path.IsEmpty() )
247  return rel_path;
248  }
249 
250  rel_path = NormalizePath( wxFileName( m_path ), &Pgm().GetLocalEnvVariables(), project_env );
251 
252  // If normalizePath failed, then rel_path will be empty, m_path is the full path.
253  if( rel_path.IsEmpty() )
254  return m_path;
255 
256  return rel_path;
257 }
Class PROJECT holds project specific data.
Definition: project.h:56
#define PROJECT_VAR_NAME
A variable name whose value holds the current project directory.
Definition: project.h:36
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: kicad.cpp:65
wxString replaceEnv(const wxString &aEnvVar, bool aFilePath=true) const
Function replaceEnv replaces path with environmental variable if applicable.
wxString NormalizePath(const wxFileName &aFilePath, const ENV_VAR_MAP *aEnvVars, const wxString &aProjectPath)
Normalizes a file path to an environmental variable, if possible.
Definition: env_paths.cpp:67
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 260 of file wizard_add_fplib.cpp.

References m_description, and m_path.

Referenced by GetAbsolutePath().

261 {
262  if( !m_description.IsEmpty() )
263  return m_description;
264 
265  wxFileName filename( m_path );
266  return filename.GetName();
267 }
wxString WIZARD_FPLIB_TABLE::LIBRARY::GetPluginName ( ) const

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

Definition at line 200 of file wizard_add_fplib.cpp.

References m_plugin, and IO_MGR::ShowType().

Referenced by GetPluginType().

201 {
202  if( !m_plugin )
203  return _( "UNKNOWN" );
204 
205  return IO_MGR::ShowType( *m_plugin );
206 }
OPT< IO_MGR::PCB_FILE_T > m_plugin
static const wxString ShowType(PCB_FILE_T aFileType)
Function ShowType returns a brief name for a plugin, given aFileType enum.
Definition: io_mgr.cpp:77
OPT<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 OPT if the type could not be autodetected.

Definition at line 120 of file wizard_add_fplib.h.

References GetPluginName(), and m_plugin.

121  {
122  return m_plugin;
123  }
OPT< 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 209 of file wizard_add_fplib.cpp.

References m_path.

Referenced by GetAbsolutePath().

210 {
211  wxFileName libPath( m_path );
212 
213  // Check if the library path belongs to the project folder
214  if( libPath.MakeRelativeTo( aBase ) && !libPath.GetFullPath().StartsWith( ".." ) )
215  {
216  return wxString( aSubstitution + "/" + libPath.GetFullPath() );
217  }
218 
219  // Probably on another drive, so the relative path will not work
220  return wxEmptyString;
221 }
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 270 of file wizard_add_fplib.cpp.

References m_path.

Referenced by GetAutoPath(), and setPluginType().

271 {
272  wxString env_path;
273 
274  if( !wxGetEnv( aEnvVar, &env_path ) )
275  return wxEmptyString;
276 
277  //return GetRelativePath( m_path, wxString( "$(" + aEnvVar + ")" ) );
278 
279  wxString result( m_path );
280 
281  if( result.Replace( env_path, wxString( "$(" + aEnvVar + ")" ) ) )
282  return result;
283 
284  return wxEmptyString;
285 }
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, and replaceEnv().

183  {
184  m_plugin = aType;
185  }
OPT< 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 162 of file wizard_add_fplib.cpp.

References INVALID, m_path, m_plugin, m_status, OK, and IO_MGR::PluginFind().

163 {
164  if( !m_plugin )
165  {
167  return false;
168  }
169 
170  std::unique_ptr<PLUGIN> p( IO_MGR::PluginFind( *m_plugin ) );
171  wxArrayString footprints;
172 
173  if( !p )
174  {
176  return false;
177  }
178 
179  try
180  {
181  p->FootprintEnumerate( footprints, m_path );
182  }
183  catch( IO_ERROR& )
184  {
186  return false;
187  }
188 
189  if( footprints.GetCount() == 0 )
190  {
192  return false;
193  }
194 
196  return true;
197 }
OPT< IO_MGR::PCB_FILE_T > m_plugin
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
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.

Referenced by GetDescription().

wxString WIZARD_FPLIB_TABLE::LIBRARY::m_path
protected
OPT<IO_MGR::PCB_FILE_T> WIZARD_FPLIB_TABLE::LIBRARY::m_plugin
protected

Definition at line 197 of file wizard_add_fplib.h.

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

STATUS WIZARD_FPLIB_TABLE::LIBRARY::m_status
protected

Definition at line 198 of file wizard_add_fplib.h.

Referenced by GetStatus(), and Test().


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