KiCad PCB EDA Suite
BOM_PLUGIN Class Reference

Class representing a Bill of Material output plugin. More...

#include <bom_plugins.h>

Public Types

typedef std::unique_ptr< BOM_PLUGINPTR
 

Public Member Functions

 BOM_PLUGIN (const wxString &aFile)
 Constructor. More...
 
bool IsOk ()
 Returns true if the plugin is ready to work, i.e. More...
 
const wxString & GetInfo () const
 Returns plugin description stored in the plugin header file (if available). More...
 
const wxFileName & GetFile () const
 Returns the file name of the plugin. More...
 
const wxString & GetName () const
 Returns the customisable plugin name. More...
 
void SetName (const wxString &aName)
 Sets the customisable plugin name. More...
 
const wxString & GetCommand () const
 Returns the command to execute the plugin. More...
 
void SetCommand (const wxString &aCommand)
 Sets the command to execute the plugin. More...
 
wxArrayString & Options ()
 Accessor to array of options. More...
 

Static Public Member Functions

static bool IsPlugin (const wxString &aFile)
 Returns true if a file name matches a recognized plugin format. More...
 

Protected Member Functions

wxString readHeader (const wxString &aEndSection)
 Reads the plugin file header. More...
 

Protected Attributes

bool m_isOk
 

true if the plugin is working (i.e. if the plugin file exists and was read

More...
 
const wxFileName m_file
 

Path to the plugin

More...
 
wxString m_name
 

User customisable name

More...
 
wxString m_cmd
 

Command to execute the plugin

More...
 
wxString m_info
 

Description of the plugin (normally from the plugin header)

More...
 
wxArrayString m_options
 

Plugin specific options

More...
 

Detailed Description

Class representing a Bill of Material output plugin.

Definition at line 37 of file bom_plugins.h.

Member Typedef Documentation

◆ PTR

typedef std::unique_ptr<BOM_PLUGIN> BOM_PLUGIN::PTR

Definition at line 40 of file bom_plugins.h.

Constructor & Destructor Documentation

◆ BOM_PLUGIN()

BOM_PLUGIN::BOM_PLUGIN ( const wxString &  aFile)

Constructor.

Parameters
aFileis path to the plugin file.

Definition at line 27 of file bom_plugins.cpp.

28  : m_file( aFile )
29 {
30  m_isOk = false;
31 
32  if( !wxFile::Exists( aFile ) )
33  {
34  m_info.Printf( _("Plugin file:\n%s\nnot found. Plugin not available."), aFile );
35  return;
36  }
37 
38  m_isOk = true;
39 
40  m_name = m_file.GetName();
41  wxString extension = m_file.GetExt().Lower();
42 
43  // Important note:
44  // On Windows the right command command to run a python script is:
45  // python <script_path>/script.py
46  // and *not* python <script_path>\script.py
47  // Otherwise the script does not find some auxiliary pythons scripts needed by this script
48  if( extension == "xsl" )
49  {
50  m_info = readHeader( "-->" );
51  m_cmd = wxString::Format( "xsltproc -o \"%%O\" \"%s\" \"%%I\"", m_file.GetFullPath() );
52  }
53  else if( extension == "py" )
54  {
55  m_info = readHeader( "\"\"\"" );
56 #ifdef __WINDOWS__
57  m_cmd = wxString::Format( "python \"%s/%s\" \"%%I\" \"%%O\"",
58  m_file.GetPath(), m_file.GetFullName() );
59 #else
60  m_cmd = wxString::Format( "python \"%s\" \"%%I\" \"%%O\"", m_file.GetFullPath() );
61 #endif
62  }
63 #ifdef __WINDOWS__
64  else if( extension == "pyw" )
65  {
66  m_info = readHeader( "\"\"\"" );
67  m_cmd = wxString::Format( "pythonw \"%s/%s\" \"%%I\" \"%%O\"",
68  m_file.GetPath(),m_file.GetFullName() );
69  }
70 #endif /* __WINDOWS__ */
71  else // fallback
72  {
73  m_cmd = m_file.GetFullPath();
74  }
75 }
wxString m_info
Description of the plugin (normally from the plugin header)
Definition: bom_plugins.h:137
wxString readHeader(const wxString &aEndSection)
Reads the plugin file header.
Definition: bom_plugins.cpp:93
wxString m_cmd
Command to execute the plugin
Definition: bom_plugins.h:134
const wxFileName m_file
Path to the plugin
Definition: bom_plugins.h:128
wxString m_name
User customisable name
Definition: bom_plugins.h:131
bool m_isOk
true if the plugin is working (i.e. if the plugin file exists and was read
Definition: bom_plugins.h:125
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205

References Format(), m_cmd, m_file, m_info, m_isOk, m_name, and readHeader().

Member Function Documentation

◆ GetCommand()

const wxString& BOM_PLUGIN::GetCommand ( ) const
inline

Returns the command to execute the plugin.

Definition at line 96 of file bom_plugins.h.

97  {
98  return m_cmd;
99  }
wxString m_cmd
Command to execute the plugin
Definition: bom_plugins.h:134

References m_cmd.

◆ GetFile()

const wxFileName& BOM_PLUGIN::GetFile ( ) const
inline

Returns the file name of the plugin.

Definition at line 71 of file bom_plugins.h.

72  {
73  return m_file;
74  }
const wxFileName m_file
Path to the plugin
Definition: bom_plugins.h:128

References m_file.

◆ GetInfo()

const wxString& BOM_PLUGIN::GetInfo ( ) const
inline

Returns plugin description stored in the plugin header file (if available).

Definition at line 63 of file bom_plugins.h.

64  {
65  return m_info;
66  }
wxString m_info
Description of the plugin (normally from the plugin header)
Definition: bom_plugins.h:137

References m_info.

◆ GetName()

const wxString& BOM_PLUGIN::GetName ( ) const
inline

Returns the customisable plugin name.

Definition at line 79 of file bom_plugins.h.

80  {
81  return m_name;
82  }
wxString m_name
User customisable name
Definition: bom_plugins.h:131

References m_name.

◆ IsOk()

bool BOM_PLUGIN::IsOk ( )
inline

Returns true if the plugin is ready to work, i.e.

if the plugin file is found an readable

Definition at line 52 of file bom_plugins.h.

52 { return m_isOk; }
bool m_isOk
true if the plugin is working (i.e. if the plugin file exists and was read
Definition: bom_plugins.h:125

References m_isOk.

◆ IsPlugin()

bool BOM_PLUGIN::IsPlugin ( const wxString &  aFile)
static

Returns true if a file name matches a recognized plugin format.

Parameters
aFileis path to the plugin file.

Definition at line 78 of file bom_plugins.cpp.

79 {
80  wxFileName fn( aFile );
81  wxString ext = fn.GetExt().Lower();
82 
83  for( const auto& pluginExt : { "xsl", "py", "pyw" } )
84  {
85  if( pluginExt == ext )
86  return true;
87  }
88 
89  return false;
90 }

Referenced by DIALOG_BOM::installPluginsList().

◆ Options()

wxArrayString& BOM_PLUGIN::Options ( )
inline

Accessor to array of options.

Definition at line 112 of file bom_plugins.h.

113  {
114  return m_options;
115  }
wxArrayString m_options
Plugin specific options
Definition: bom_plugins.h:140

References m_options.

◆ readHeader()

wxString BOM_PLUGIN::readHeader ( const wxString &  aEndSection)
protected

Reads the plugin file header.

Parameters
aEndSectionis a string marking end of the header.

Definition at line 93 of file bom_plugins.cpp.

94 {
95  if( aEndSection.IsEmpty() )
96  return wxEmptyString;
97 
98  wxFile fdata( m_file.GetFullPath() ); // dtor will close the file
99  wxString data;
100 
101  if( !fdata.ReadAll( &data ) )
102  return wxEmptyString;
103 
104  const wxString header( "@package" );
105 
106  // Extract substring between @package and endsection
107  int strstart = data.Find( header );
108 
109  if( strstart == wxNOT_FOUND )
110  return wxEmptyString;
111 
112  strstart += header.Length();
113  int strend = data.find( aEndSection, strstart );
114 
115  if( strend == wxNOT_FOUND)
116  return wxEmptyString;
117 
118  // Remove empty line if any
119  while( data[strstart] < ' ' )
120  strstart++;
121 
122  return data.SubString( strstart, strend - 1 );
123 }
const wxFileName m_file
Path to the plugin
Definition: bom_plugins.h:128

References m_file.

Referenced by BOM_PLUGIN().

◆ SetCommand()

void BOM_PLUGIN::SetCommand ( const wxString &  aCommand)
inline

Sets the command to execute the plugin.

Definition at line 104 of file bom_plugins.h.

105  {
106  m_cmd = aCommand;
107  }
wxString m_cmd
Command to execute the plugin
Definition: bom_plugins.h:134

References m_cmd.

◆ SetName()

void BOM_PLUGIN::SetName ( const wxString &  aName)
inline

Sets the customisable plugin name.

Parameters
aNameis the new name.

Definition at line 88 of file bom_plugins.h.

89  {
90  m_name = aName;
91  }
wxString m_name
User customisable name
Definition: bom_plugins.h:131

References m_name.

Member Data Documentation

◆ m_cmd

wxString BOM_PLUGIN::m_cmd
protected

Command to execute the plugin

Definition at line 134 of file bom_plugins.h.

Referenced by BOM_PLUGIN(), GetCommand(), and SetCommand().

◆ m_file

const wxFileName BOM_PLUGIN::m_file
protected

Path to the plugin

Definition at line 128 of file bom_plugins.h.

Referenced by BOM_PLUGIN(), GetFile(), and readHeader().

◆ m_info

wxString BOM_PLUGIN::m_info
protected

Description of the plugin (normally from the plugin header)

Definition at line 137 of file bom_plugins.h.

Referenced by BOM_PLUGIN(), and GetInfo().

◆ m_isOk

bool BOM_PLUGIN::m_isOk
protected

true if the plugin is working (i.e. if the plugin file exists and was read

Definition at line 125 of file bom_plugins.h.

Referenced by BOM_PLUGIN(), and IsOk().

◆ m_name

wxString BOM_PLUGIN::m_name
protected

User customisable name

Definition at line 131 of file bom_plugins.h.

Referenced by BOM_PLUGIN(), GetName(), and SetName().

◆ m_options

wxArrayString BOM_PLUGIN::m_options
protected

Plugin specific options

Definition at line 140 of file bom_plugins.h.

Referenced by Options().


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