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.

147 lines
3.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. * @author Maciej Suminski <maciej.suminski@cern.ch>
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 3
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, you may find one here:
  19. * https://www.gnu.org/licenses/gpl-3.0.html
  20. * or you may search the http://www.gnu.org website for the version 3 license,
  21. * or you may write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  23. */
  24. #ifndef BOM_GENERATOR_HANDLERS_H
  25. #define BOM_GENERATOR_HANDLERS_H
  26. #include <wx/arrstr.h>
  27. #include <wx/file.h>
  28. #include <wx/filename.h>
  29. #include <memory>
  30. /**
  31. * Class handling a Bill of Material output generator.
  32. * A Material output generator is an external application called by Eeschema to create
  33. * a BOM from our intermediate xml netlist.
  34. * A generator can be a script or an executable that can read the intermediate xml netlist
  35. * file and generates a output (the BOM file)
  36. */
  37. class BOM_GENERATOR_HANDLER
  38. {
  39. public:
  40. typedef std::unique_ptr<BOM_GENERATOR_HANDLER> PTR;
  41. /**
  42. * Constructor.
  43. * @param aFile is path to the plugin file.
  44. */
  45. BOM_GENERATOR_HANDLER( const wxString& aFile );
  46. /**
  47. * Returns true if the plugin is ready to work, i.e. if the plugin file
  48. * is found an readable
  49. */
  50. bool IsOk() { return m_isOk; }
  51. /**
  52. * Returns true if a file name matches a recognized plugin format.
  53. * @param aFile is path to the plugin file.
  54. */
  55. static bool IsValidGenerator( const wxString& aFile );
  56. /**
  57. * Returns plugin description stored in the plugin header file (if available).
  58. */
  59. const wxString& GetInfo() const
  60. {
  61. return m_info;
  62. }
  63. /**
  64. * Returns the file name of the plugin.
  65. */
  66. const wxFileName& GetFile() const
  67. {
  68. return m_file;
  69. }
  70. /**
  71. * Returns the customisable plugin name.
  72. */
  73. const wxString& GetName() const
  74. {
  75. return m_name;
  76. }
  77. /**
  78. * Sets the customisable plugin name.
  79. * @param aName is the new name.
  80. */
  81. void SetName( const wxString& aName )
  82. {
  83. m_name = aName;
  84. }
  85. /**
  86. * Returns the command to execute the plugin.
  87. */
  88. const wxString& GetCommand() const
  89. {
  90. return m_cmd;
  91. }
  92. /**
  93. * Sets the command to execute the plugin.
  94. */
  95. void SetCommand( const wxString& aCommand )
  96. {
  97. m_cmd = aCommand;
  98. }
  99. /**
  100. * Accessor to array of options.
  101. */
  102. wxArrayString& Options()
  103. {
  104. return m_options;
  105. }
  106. protected:
  107. /**
  108. * Reads the plugin file header.
  109. * @param aEndSection is a string marking end of the header.
  110. */
  111. wxString readHeader( const wxString& aEndSection );
  112. ///> true if the plugin is working (i.e. if the plugin file exists and was read
  113. bool m_isOk;
  114. ///> Path to the plugin
  115. const wxFileName m_file;
  116. ///> User customisable name
  117. wxString m_name;
  118. ///> Command to execute the plugin
  119. wxString m_cmd;
  120. ///> Description of the plugin (normally from the plugin header)
  121. wxString m_info;
  122. ///> Plugin specific options
  123. wxArrayString m_options;
  124. };
  125. #endif /* BOM_GENERATOR_HANDLERS_H */