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.

215 lines
6.0 KiB

5 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2017-2021 KiCad Developers, see AUTHORS.txt for contributors.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version 2
  9. * of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, you may find one here:
  18. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  19. * or you may search the http://www.gnu.org website for the version 2 license,
  20. * or you may write to the Free Software Foundation, Inc.,
  21. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  22. */
  23. /**
  24. * @file action_plugin.h
  25. * @brief Class PCBNEW_ACTION_PLUGINS
  26. */
  27. #ifndef CLASS_ACTION_PLUGIN_H
  28. #define CLASS_ACTION_PLUGIN_H
  29. #include <vector>
  30. #include <pcb_edit_frame.h>
  31. /**
  32. * This is the parent class from where any action plugin class must derive.
  33. */
  34. class ACTION_PLUGIN
  35. {
  36. public:
  37. ACTION_PLUGIN() : m_actionMenuId( 0 ), m_actionButtonId( 0 ),
  38. show_on_toolbar( false ) {}
  39. virtual ~ACTION_PLUGIN();
  40. /**
  41. * @return the category name of the action (to be able to group action under the same submenu).
  42. */
  43. virtual wxString GetCategoryName() = 0;
  44. /**
  45. * @return the name of the action.
  46. */
  47. virtual wxString GetName() = 0;
  48. /**
  49. * @return a description of the action plugin.
  50. */
  51. virtual wxString GetDescription() = 0;
  52. /**
  53. * @return true if button should be shown on top toolbar.
  54. */
  55. virtual bool GetShowToolbarButton() = 0;
  56. /**
  57. * @param aDark set to true if requesting dark theme icon.
  58. * @return a path to icon for the action plugin button.
  59. */
  60. virtual wxString GetIconFileName( bool aDark ) = 0;
  61. /**
  62. * @return a path this plugin was loaded from.
  63. */
  64. virtual wxString GetPluginPath() = 0;
  65. /**
  66. * This method gets the pointer to the object from where this action constructs.
  67. *
  68. * @return it's a void pointer, as it could be a PyObject or any other
  69. */
  70. virtual void* GetObject() = 0;
  71. /**
  72. * This method the the action.
  73. */
  74. virtual void Run() = 0;
  75. /**
  76. * It's the standard method of a "ACTION_PLUGIN" to register itself into the ACTION_PLUGINS
  77. * singleton manager.
  78. */
  79. void register_action();
  80. // association between the plugin and its menu id
  81. // m_actionMenuId set to 0 means the corresponding menuitem to call this
  82. // action is not yet created
  83. int m_actionMenuId;
  84. // Same for button id
  85. int m_actionButtonId;
  86. // Icon for the action button and menu entry
  87. wxBitmap iconBitmap;
  88. // If show_on_toolbar is true a button will be added to top toolbar
  89. bool show_on_toolbar;
  90. };
  91. /**
  92. * Mainly static. Storing all plugins information.
  93. */
  94. class ACTION_PLUGINS
  95. {
  96. public:
  97. /**
  98. * An action calls this static method when it wants to register itself
  99. * into the system actions.
  100. *
  101. * @param aAction is the action plugin to be registered.
  102. */
  103. static void register_action( ACTION_PLUGIN* aAction );
  104. /**
  105. * Deregister an object which builds a action.
  106. *
  107. * Lookup on the vector calling GetObject until find, then removed and deleted.
  108. *
  109. * @param aObject is the action plugin object to be deregistered.
  110. */
  111. static bool deregister_object( void* aObject );
  112. /**
  113. * @param aName is the action plugin name.
  114. * @return a action object by it's name or NULL if it isn't available.
  115. */
  116. static ACTION_PLUGIN* GetAction( const wxString& aName );
  117. /**
  118. * Associate a menu id to an action plugin.
  119. *
  120. * @param aIndex is the action index.
  121. * @param idMenu is the associated menuitem ID.
  122. */
  123. static void SetActionMenu( int aIndex, int idMenu );
  124. /**
  125. * Find action plugin associated to a menu ID.
  126. *
  127. * @param aMenu is the menu id (defined with SetActionMenu).
  128. * @return the associated ACTION_PLUGIN (or null if not found).
  129. */
  130. static ACTION_PLUGIN* GetActionByMenu( int aMenu );
  131. /**
  132. * Associate a button id to an action plugin.
  133. *
  134. * @param aAction is the action.
  135. * @param idButton is the associated menuitem ID.
  136. */
  137. static void SetActionButton( ACTION_PLUGIN* aAction, int idButton );
  138. /**
  139. * Find action plugin associated to a button ID.
  140. *
  141. * @param aButton is the button id (defined with SetActionButton).
  142. * @return the associated ACTION_PLUGIN (or null if not found).
  143. */
  144. static ACTION_PLUGIN* GetActionByButton( int aButton );
  145. /**
  146. * Find action plugin by module path.
  147. *
  148. * @param aPath is the path of plugin.
  149. * @return the corresponding ACTION_PLUGIN (or null if not found).
  150. */
  151. static ACTION_PLUGIN* GetActionByPath( const wxString& aPath );
  152. /**
  153. * @param aIndex is the action index in list.
  154. * @return a action object by it's number or NULL if it isn't available.
  155. */
  156. static ACTION_PLUGIN* GetAction( int aIndex );
  157. /**
  158. * @return the number of actions available into the system.
  159. */
  160. static int GetActionsCount();
  161. /**
  162. * @return true if an action running right now otherwise false.
  163. */
  164. static bool IsActionRunning();
  165. /**
  166. * @param aRunning sets whether an action is running now.
  167. */
  168. static void SetActionRunning( bool aRunning );
  169. /**
  170. * Unload (deregister) all action plugins.
  171. */
  172. static void UnloadAll();
  173. private:
  174. /**
  175. * ACTION_PLUGIN system wide static list.
  176. */
  177. static std::vector<ACTION_PLUGIN*> m_actionsList;
  178. static bool m_actionRunning;
  179. };
  180. #endif /* PCBNEW_ACTION_PLUGINS_H */