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.4 KiB

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