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.

223 lines
6.2 KiB

5 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright The 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 the name of the Python class defining the action
  50. */
  51. virtual wxString GetClassName() = 0;
  52. /**
  53. * @return a description of the action plugin.
  54. */
  55. virtual wxString GetDescription() = 0;
  56. /**
  57. * @return true if button should be shown on top toolbar.
  58. */
  59. virtual bool GetShowToolbarButton() = 0;
  60. /**
  61. * @param aDark set to true if requesting dark theme icon.
  62. * @return a path to icon for the action plugin button.
  63. */
  64. virtual wxString GetIconFileName( bool aDark ) = 0;
  65. /**
  66. * @return a path this plugin was loaded from.
  67. */
  68. virtual wxString GetPluginPath() = 0;
  69. /**
  70. * This method gets the pointer to the object from where this action constructs.
  71. *
  72. * @return it's a void pointer, as it could be a PyObject or any other
  73. */
  74. virtual void* GetObject() = 0;
  75. /**
  76. * This method the the action.
  77. */
  78. virtual void Run() = 0;
  79. /**
  80. * It's the standard method of a "ACTION_PLUGIN" to register itself into the ACTION_PLUGINS
  81. * singleton manager.
  82. */
  83. void register_action();
  84. // association between the plugin and its menu id
  85. // m_actionMenuId set to 0 means the corresponding menuitem to call this
  86. // action is not yet created
  87. int m_actionMenuId;
  88. // Same for button id
  89. int m_actionButtonId;
  90. // Icon for the action button and menu entry
  91. wxBitmap iconBitmap;
  92. // If show_on_toolbar is true a button will be added to top toolbar
  93. bool show_on_toolbar;
  94. };
  95. /**
  96. * Mainly static. Storing all plugins information.
  97. */
  98. class ACTION_PLUGINS
  99. {
  100. public:
  101. /**
  102. * An action calls this static method when it wants to register itself
  103. * into the system actions.
  104. *
  105. * @param aAction is the action plugin to be registered.
  106. */
  107. static void register_action( ACTION_PLUGIN* aAction );
  108. /**
  109. * Deregister an object which builds a action.
  110. *
  111. * Lookup on the vector calling GetObject until find, then removed and deleted.
  112. *
  113. * @param aObject is the action plugin object to be deregistered.
  114. */
  115. static bool deregister_object( void* aObject );
  116. /**
  117. * @param aName is the action plugin name.
  118. * @return a action object by it's name or NULL if it isn't available.
  119. */
  120. static ACTION_PLUGIN* GetAction( const wxString& aName );
  121. /**
  122. * Associate a menu id to an action plugin.
  123. *
  124. * @param aIndex is the action index.
  125. * @param idMenu is the associated menuitem ID.
  126. */
  127. static void SetActionMenu( int aIndex, int idMenu );
  128. /**
  129. * Find action plugin associated to a menu ID.
  130. *
  131. * @param aMenu is the menu id (defined with SetActionMenu).
  132. * @return the associated ACTION_PLUGIN (or null if not found).
  133. */
  134. static ACTION_PLUGIN* GetActionByMenu( int aMenu );
  135. /**
  136. * Associate a button id to an action plugin.
  137. *
  138. * @param aAction is the action.
  139. * @param idButton is the associated menuitem ID.
  140. */
  141. static void SetActionButton( ACTION_PLUGIN* aAction, int idButton );
  142. /**
  143. * Find action plugin associated to a button ID.
  144. *
  145. * @param aButton is the button id (defined with SetActionButton).
  146. * @return the associated ACTION_PLUGIN (or null if not found).
  147. */
  148. static ACTION_PLUGIN* GetActionByButton( int aButton );
  149. /**
  150. * Find action plugin by module path.
  151. *
  152. * @param aPath is the path of plugin.
  153. * @return the corresponding ACTION_PLUGIN (or null if not found).
  154. */
  155. static ACTION_PLUGIN* GetActionByPath( const wxString& aPath );
  156. /**
  157. * @param aIndex is the action index in list.
  158. * @return a action object by it's number or NULL if it isn't available.
  159. */
  160. static ACTION_PLUGIN* GetAction( int aIndex );
  161. /**
  162. * @return the number of actions available into the system.
  163. */
  164. static int GetActionsCount();
  165. /**
  166. * @return true if an action running right now otherwise false.
  167. */
  168. static bool IsActionRunning();
  169. /**
  170. * @param aRunning sets whether an action is running now.
  171. */
  172. static void SetActionRunning( bool aRunning );
  173. /**
  174. * Unload (deregister) all action plugins.
  175. */
  176. static void UnloadAll();
  177. private:
  178. /**
  179. * ACTION_PLUGIN system wide static list.
  180. */
  181. static std::vector<ACTION_PLUGIN*> m_actionsList;
  182. static bool m_actionRunning;
  183. };
  184. typedef std::variant<ACTION_PLUGIN*, const PLUGIN_ACTION*> LEGACY_OR_API_PLUGIN;
  185. #endif /* PCBNEW_ACTION_PLUGINS_H */