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.

143 lines
3.4 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_PLUGINS_H
  25. #define BOM_PLUGINS_H
  26. #include <wx/arrstr.h>
  27. #include <wx/file.h>
  28. #include <wx/filename.h>
  29. #include <memory>
  30. /**
  31. * Class representing a Bill of Material output plugin.
  32. */
  33. class BOM_PLUGIN
  34. {
  35. public:
  36. typedef std::unique_ptr<BOM_PLUGIN> PTR;
  37. /**
  38. * Constructor.
  39. * @param aFile is path to the plugin file.
  40. */
  41. BOM_PLUGIN( const wxString& aFile );
  42. /**
  43. * Returns true if the plugin is ready to work, i.e. if the plugin file
  44. * is found an readable
  45. */
  46. bool IsOk() { return m_isOk; }
  47. /**
  48. * Returns true if a file name matches a recognized plugin format.
  49. * @param aFile is path to the plugin file.
  50. */
  51. static bool IsPlugin( const wxString& aFile );
  52. /**
  53. * Returns plugin description stored in the plugin header file (if available).
  54. */
  55. const wxString& GetInfo() const
  56. {
  57. return m_info;
  58. }
  59. /**
  60. * Returns the file name of the plugin.
  61. */
  62. const wxFileName& GetFile() const
  63. {
  64. return m_file;
  65. }
  66. /**
  67. * Returns the customisable plugin name.
  68. */
  69. const wxString& GetName() const
  70. {
  71. return m_name;
  72. }
  73. /**
  74. * Sets the customisable plugin name.
  75. * @param aName is the new name.
  76. */
  77. void SetName( const wxString& aName )
  78. {
  79. m_name = aName;
  80. }
  81. /**
  82. * Returns the command to execute the plugin.
  83. */
  84. const wxString& GetCommand() const
  85. {
  86. return m_cmd;
  87. }
  88. /**
  89. * Sets the command to execute the plugin.
  90. */
  91. void SetCommand( const wxString& aCommand )
  92. {
  93. m_cmd = aCommand;
  94. }
  95. /**
  96. * Accessor to array of options.
  97. */
  98. wxArrayString& Options()
  99. {
  100. return m_options;
  101. }
  102. protected:
  103. /**
  104. * Reads the plugin file header.
  105. * @param aEndSection is a string marking end of the header.
  106. */
  107. wxString readHeader( const wxString& aEndSection );
  108. ///> true if the plugin is working (i.e. if the plugin file exists and was read
  109. bool m_isOk;
  110. ///> Path to the plugin
  111. const wxFileName m_file;
  112. ///> User customisable name
  113. wxString m_name;
  114. ///> Command to execute the plugin
  115. wxString m_cmd;
  116. ///> Description of the plugin (normally from the plugin header)
  117. wxString m_info;
  118. ///> Plugin specific options
  119. wxArrayString m_options;
  120. };
  121. #endif /* BOM_PLUGINS_H */