You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

175 lines
4.7 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2018 CERN
  5. * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
  6. *
  7. * @author Maciej Suminski <maciej.suminski@cern.ch>
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version 3
  12. * of the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, you may find one here:
  21. * https://www.gnu.org/licenses/gpl-3.0.html
  22. * or you may search the http://www.gnu.org website for the version 3 license,
  23. * or you may write to the Free Software Foundation, Inc.,
  24. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  25. */
  26. #ifndef BOM_GENERATOR_HANDLERS_H
  27. #define BOM_GENERATOR_HANDLERS_H
  28. #include <wx/arrstr.h>
  29. #include <wx/file.h>
  30. #include <wx/filename.h>
  31. #include <memory>
  32. extern const wxChar BOM_TRACE[];
  33. /**
  34. * Bill of material output generator.
  35. *
  36. * A Material output generator is an external application called by Eeschema to create
  37. * a BOM from our intermediate XML netlist. A generator can be a script or an executable
  38. * that can read the intermediate XML netlist file and generates a output (the BOM file)
  39. */
  40. class BOM_GENERATOR_HANDLER
  41. {
  42. public:
  43. typedef std::unique_ptr<BOM_GENERATOR_HANDLER> PTR;
  44. /**
  45. * @param aFile is path to the plugin file.
  46. */
  47. BOM_GENERATOR_HANDLER( const wxString& aFile );
  48. /**
  49. * Return true if the plugin is ready to work, i.e. if the plugin file is found and readable.
  50. */
  51. bool IsOk() { return m_isOk; }
  52. /**
  53. * Return true if a file name matches a recognized plugin format.
  54. *
  55. * @param aFile is path to the plugin file.
  56. */
  57. static bool IsValidGenerator( const wxString& aFile );
  58. /**
  59. * Return plugin description stored in the plugin header file (if available).
  60. */
  61. const wxString& GetInfo() const
  62. {
  63. return m_info;
  64. }
  65. /**
  66. * Return the file name of the plugin.
  67. */
  68. const wxFileName& GetFile() const
  69. {
  70. return m_file;
  71. }
  72. wxString GetStoredPath() const { return m_storedPath; }
  73. /**
  74. * Returns the calculated path to the plugin: if the path is already absolute and exists,
  75. * just return it. Otherwise if the path is just a filename, look for that file in the user
  76. * and system plugin directories and return the first one found. If neither is found, just
  77. * return m_file.
  78. *
  79. * @return the full path to the plugin
  80. */
  81. wxFileName FindFilePath() const;
  82. /**
  83. * Return the customisable plugin name.
  84. */
  85. const wxString& GetName() const
  86. {
  87. return m_name;
  88. }
  89. /**
  90. * Set the customisable plugin name.
  91. *
  92. * @param aName is the new name.
  93. */
  94. void SetName( const wxString& aName )
  95. {
  96. m_name = aName;
  97. }
  98. /**
  99. * Return the command to execute the plugin.
  100. */
  101. const wxString& GetCommand() const
  102. {
  103. return m_cmd;
  104. }
  105. /**
  106. * Set the command to execute the plugin.
  107. */
  108. void SetCommand( const wxString& aCommand )
  109. {
  110. m_cmd = aCommand;
  111. }
  112. /**
  113. * Accessor to array of options.
  114. */
  115. wxArrayString& Options()
  116. {
  117. return m_options;
  118. }
  119. protected:
  120. /**
  121. * Read the plugin file header.
  122. *
  123. * @param aEndSection is a string marking end of the header.
  124. */
  125. wxString readHeader( const wxString& aEndSection );
  126. /**
  127. * Extracts the output BOM file's extension, including the '.', from the
  128. * plugin file header. If the output extension cannot be determined from
  129. * the plugin header, returns wxEmptyString.
  130. * @param aHeader is the plugin file's header, as returned by readHeader()
  131. **/
  132. static wxString getOutputExtension( const wxString& aHeader );
  133. ///< true if the plugin is working (i.e. if the plugin file exists and was read
  134. bool m_isOk;
  135. ///< Path to the plugin
  136. wxFileName m_file;
  137. ///< Path to the plugin stored in config (can be absolute or just a filename)
  138. const wxString m_storedPath;
  139. ///< User customisable name
  140. wxString m_name;
  141. ///< Command to execute the plugin
  142. wxString m_cmd;
  143. ///< Description of the plugin (normally from the plugin header)
  144. wxString m_info;
  145. ///< Plugin specific options
  146. wxArrayString m_options;
  147. };
  148. #endif /* BOM_GENERATOR_HANDLERS_H */