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.

173 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. /**
  44. * @param aFile is path to the plugin file.
  45. */
  46. BOM_GENERATOR_HANDLER( const wxString& aFile );
  47. /**
  48. * Return true if the plugin is ready to work, i.e. if the plugin file is found and readable.
  49. */
  50. bool IsOk() { return m_isOk; }
  51. /**
  52. * Return true if a file name matches a recognized plugin format.
  53. *
  54. * @param aFile is path to the plugin file.
  55. */
  56. static bool IsValidGenerator( const wxString& aFile );
  57. /**
  58. * Return plugin description stored in the plugin header file (if available).
  59. */
  60. const wxString& GetInfo() const
  61. {
  62. return m_info;
  63. }
  64. /**
  65. * Return the file name of the plugin.
  66. */
  67. const wxFileName& GetFile() const
  68. {
  69. return m_file;
  70. }
  71. wxString GetStoredPath() const { return m_storedPath; }
  72. /**
  73. * Returns the calculated path to the plugin: if the path is already absolute and exists,
  74. * just return it. Otherwise if the path is just a filename, look for that file in the user
  75. * and system plugin directories and return the first one found. If neither is found, just
  76. * return m_file.
  77. *
  78. * @return the full path to the plugin
  79. */
  80. wxFileName FindFilePath() const;
  81. /**
  82. * Return the customisable plugin name.
  83. */
  84. const wxString& GetName() const
  85. {
  86. return m_name;
  87. }
  88. /**
  89. * Set the customisable plugin name.
  90. *
  91. * @param aName is the new name.
  92. */
  93. void SetName( const wxString& aName )
  94. {
  95. m_name = aName;
  96. }
  97. /**
  98. * Return the command to execute the plugin.
  99. */
  100. const wxString& GetCommand() const
  101. {
  102. return m_cmd;
  103. }
  104. /**
  105. * Set the command to execute the plugin.
  106. */
  107. void SetCommand( const wxString& aCommand )
  108. {
  109. m_cmd = aCommand;
  110. }
  111. /**
  112. * Accessor to array of options.
  113. */
  114. wxArrayString& Options()
  115. {
  116. return m_options;
  117. }
  118. protected:
  119. /**
  120. * Read the plugin file header.
  121. *
  122. * @param aEndSection is a string marking end of the header.
  123. */
  124. wxString readHeader( const wxString& aEndSection );
  125. /**
  126. * Extracts the output BOM file's extension, including the '.', from the
  127. * plugin file header. If the output extension cannot be determined from
  128. * the plugin header, returns wxEmptyString.
  129. * @param aHeader is the plugin file's header, as returned by readHeader()
  130. **/
  131. static wxString getOutputExtension( const wxString& aHeader );
  132. ///< true if the plugin is working (i.e. if the plugin file exists and was read
  133. bool m_isOk;
  134. ///< Path to the plugin
  135. wxFileName m_file;
  136. ///< Path to the plugin stored in config (can be absolute or just a filename)
  137. const wxString m_storedPath;
  138. ///< User customisable name
  139. wxString m_name;
  140. ///< Command to execute the plugin
  141. wxString m_cmd;
  142. ///< Description of the plugin (normally from the plugin header)
  143. wxString m_info;
  144. ///< Plugin specific options
  145. wxArrayString m_options;
  146. };
  147. #endif /* BOM_GENERATOR_HANDLERS_H */