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.

173 lines
4.7 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 CHANGELOG.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 class_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 <wxPcbStruct.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. ACTION_PLUGIN() {}
  40. virtual ~ACTION_PLUGIN();
  41. /**
  42. * Function GetCategoryName
  43. * @return the category name of the action (to be able to group action under the same submenu)
  44. */
  45. virtual wxString GetCategoryName() = 0;
  46. /**
  47. * Function GetName
  48. * @return the name of the action
  49. */
  50. virtual wxString GetName() = 0;
  51. /**
  52. * Function GetDescription
  53. * @return a description of the action plugin
  54. */
  55. virtual wxString GetDescription() = 0;
  56. /**
  57. * Function GetObject
  58. * This method gets the pointer to the object from where this action constructs
  59. * @return it's a void pointer, as it could be a PyObject or any other
  60. */
  61. virtual void* GetObject() = 0;
  62. /**
  63. * Function Run
  64. * This method the the action
  65. */
  66. virtual void Run() = 0;
  67. /**
  68. * Function register_action
  69. * It's the standard method of a "ACTION_PLUGIN" to register itself into
  70. * the ACTION_PLUGINS singleton manager
  71. */
  72. void register_action();
  73. };
  74. /**
  75. * Class ACTION_PLUGINS
  76. * Mainly static. Storing all plugins informations.
  77. */
  78. class ACTION_PLUGINS
  79. {
  80. private:
  81. /**
  82. * ACTION_PLUGIN system wide static list
  83. */
  84. static std::vector<ACTION_PLUGIN*> m_Actions;
  85. /**
  86. * system wide static association between Plugin and menu id
  87. */
  88. static std::vector<int> m_ActionsMenu;
  89. public:
  90. /**
  91. * Function register_action
  92. * An action calls this static method when it wants to register itself
  93. * into the system actions
  94. *
  95. * @param aAction is the action plugin to be registered
  96. */
  97. static void register_action( ACTION_PLUGIN* aAction );
  98. /**
  99. * Function deregister_object
  100. * Anyone calls this method to deregister an object which builds a action,
  101. * it will lookup on the vector calling GetObject until find, then removed
  102. * and deleted
  103. *
  104. * @param aObject is the action plugin object to be deregistered
  105. */
  106. static bool deregister_object( void* aObject );
  107. /**
  108. * Function GetAction
  109. * @param aName is the action plugin name
  110. * @return a action object by it's name or NULL if it isn't available.
  111. */
  112. static ACTION_PLUGIN* GetAction( wxString aName );
  113. /**
  114. * Function SetActionMenu
  115. * Associate a menu id to an action plugin
  116. * @param aInded is the action index
  117. * @param idMenu is the associated menuitem id
  118. */
  119. static void SetActionMenu( int aIndex, int idMenu );
  120. /**
  121. * Function GetActionMenu
  122. * Provide menu id for a plugin index
  123. * @param aIndex is the action index
  124. * @return associated menuitem id
  125. */
  126. static int GetActionMenu( int aIndex );
  127. /**
  128. * Function GetActionByMenu
  129. * find action plugin associated to a menu id
  130. * @param menu is the menu id (defined with SetActionMenu)
  131. * @return the associated ACTION_PLUGIN (or null if not found)
  132. */
  133. static ACTION_PLUGIN* GetActionByMenu( int menu );
  134. /**
  135. * Function GetAction
  136. * @return a action object by it's number or NULL if it isn't available.
  137. * @param aIndex is the action index in list
  138. */
  139. static ACTION_PLUGIN* GetAction( int aIndex );
  140. /**
  141. * Function GetActionsCount
  142. * @return the number of actions available into the system
  143. */
  144. static int GetActionsCount();
  145. };
  146. #endif /* PCBNEW_ACTION_PLUGINS_H */