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...
 
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

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

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 ( const wxString &  aFile)

Constructor.

Parameters
aFileis path to the plugin file.

Definition at line 27 of file bom_plugins.cpp.

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

28  : m_file( aFile )
29 {
30  if( !wxFile::Exists( aFile ) )
31  throw std::runtime_error( ( _( "Cannot open plugin " ) + aFile ).ToStdString() );
32 
33  m_name = m_file.GetName();
34  wxString extension = m_file.GetExt().Lower();
35 
36  // Important note:
37  // On Windows the right command command to run a python script is:
38  // python <script_path>/script.py
39  // and *not* python <script_path>\script.py
40  // Otherwise the script does not find some auxiliary pythons scripts needed by this script
41  if( extension == "xsl" )
42  {
43  m_info = readHeader( "-->" );
44  m_cmd = wxString::Format( "xsltproc -o \"%%O\" \"%s\" \"%%I\"", m_file.GetFullPath() );
45  }
46  else if( extension == "py" )
47  {
48  m_info = readHeader( "\"\"\"" );
49 #ifdef __WINDOWS__
50  m_cmd = wxString::Format( "python \"%s/%s\" \"%%I\" \"%%O\"",
51  m_file.GetPath(), m_file.GetFullName() );
52 #else
53  m_cmd = wxString::Format( "python \"%s\" \"%%I\" \"%%O\"", m_file.GetFullPath() );
54 #endif
55  }
56 #ifdef __WINDOWS__
57  else if( extension == "pyw" )
58  {
59  m_info = readHeader( "\"\"\"" );
60  m_cmd = wxString::Format( "pythonw \"%s/%s\" \"%%I\" \"%%O\"",
61  m_file.GetPath(),m_file.GetFullName() );
62  }
63 #endif /* __WINDOWS__ */
64  else // fallback
65  {
66  m_cmd = m_file.GetFullPath();
67  }
68 }
wxString m_info
Description of the plugin (normally from the plugin header)
Definition: bom_plugins.h:128
wxString readHeader(const wxString &aEndSection)
Reads the plugin file header.
Definition: bom_plugins.cpp:86
wxString m_cmd
Command to execute the plugin
Definition: bom_plugins.h:125
const wxFileName m_file
Path to the plugin
Definition: bom_plugins.h:119
wxString m_name
User customisable name
Definition: bom_plugins.h:122
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

Member Function Documentation

const wxString& BOM_PLUGIN::GetCommand ( ) const
inline

Returns the command to execute the plugin.

Definition at line 90 of file bom_plugins.h.

References m_cmd.

91  {
92  return m_cmd;
93  }
wxString m_cmd
Command to execute the plugin
Definition: bom_plugins.h:125
const wxFileName& BOM_PLUGIN::GetFile ( ) const
inline

Returns the file name of the plugin.

Definition at line 65 of file bom_plugins.h.

References m_file.

66  {
67  return m_file;
68  }
const wxFileName m_file
Path to the plugin
Definition: bom_plugins.h:119
const wxString& BOM_PLUGIN::GetInfo ( ) const
inline

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

Definition at line 57 of file bom_plugins.h.

References m_info.

58  {
59  return m_info;
60  }
wxString m_info
Description of the plugin (normally from the plugin header)
Definition: bom_plugins.h:128
const wxString& BOM_PLUGIN::GetName ( ) const
inline

Returns the customisable plugin name.

Definition at line 73 of file bom_plugins.h.

References m_name.

74  {
75  return m_name;
76  }
wxString m_name
User customisable name
Definition: bom_plugins.h:122
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 71 of file bom_plugins.cpp.

Referenced by DIALOG_BOM::installPluginsList().

72 {
73  wxFileName fn( aFile );
74  wxString ext = fn.GetExt().Lower();
75 
76  for( const auto& pluginExt : { "xsl", "py", "pyw" } )
77  {
78  if( pluginExt == ext )
79  return true;
80  }
81 
82  return false;
83 }
wxArrayString& BOM_PLUGIN::Options ( )
inline

Accessor to array of options.

Definition at line 106 of file bom_plugins.h.

References m_options, and readHeader().

107  {
108  return m_options;
109  }
wxArrayString m_options
Plugin specific options
Definition: bom_plugins.h:131
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 86 of file bom_plugins.cpp.

References m_file.

Referenced by BOM_PLUGIN(), and Options().

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

Sets the command to execute the plugin.

Definition at line 98 of file bom_plugins.h.

References m_cmd.

99  {
100  m_cmd = aCommand;
101  }
wxString m_cmd
Command to execute the plugin
Definition: bom_plugins.h:125
void BOM_PLUGIN::SetName ( const wxString &  aName)
inline

Sets the customisable plugin name.

Parameters
aNameis the new name.

Definition at line 82 of file bom_plugins.h.

References m_name.

Referenced by DIALOG_BOM::addPlugin().

83  {
84  m_name = aName;
85  }
wxString m_name
User customisable name
Definition: bom_plugins.h:122

Member Data Documentation

wxString BOM_PLUGIN::m_cmd
protected

Command to execute the plugin

Definition at line 125 of file bom_plugins.h.

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

const wxFileName BOM_PLUGIN::m_file
protected

Path to the plugin

Definition at line 119 of file bom_plugins.h.

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

wxString BOM_PLUGIN::m_info
protected

Description of the plugin (normally from the plugin header)

Definition at line 128 of file bom_plugins.h.

Referenced by BOM_PLUGIN(), and GetInfo().

wxString BOM_PLUGIN::m_name
protected

User customisable name

Definition at line 122 of file bom_plugins.h.

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

wxArrayString BOM_PLUGIN::m_options
protected

Plugin specific options

Definition at line 131 of file bom_plugins.h.

Referenced by Options().


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