KiCad PCB EDA Suite
ACTION_PLUGINS Class Reference

Mainly static. More...

#include <action_plugin.h>

Static Public Member Functions

static void register_action (ACTION_PLUGIN *aAction)
 An action calls this static method when it wants to register itself into the system actions. More...
 
static bool deregister_object (void *aObject)
 Deregister an object which builds a action. More...
 
static ACTION_PLUGINGetAction (const wxString &aName)
 
static void SetActionMenu (int aIndex, int idMenu)
 Associate a menu id to an action plugin. More...
 
static ACTION_PLUGINGetActionByMenu (int aMenu)
 Find action plugin associated to a menu ID. More...
 
static void SetActionButton (ACTION_PLUGIN *aAction, int idButton)
 Associate a button id to an action plugin. More...
 
static ACTION_PLUGINGetActionByButton (int aButton)
 Find action plugin associated to a button ID. More...
 
static ACTION_PLUGINGetActionByPath (const wxString &aPath)
 Find action plugin by module path. More...
 
static ACTION_PLUGINGetAction (int aIndex)
 
static int GetActionsCount ()
 
static bool IsActionRunning ()
 
static void SetActionRunning (bool aRunning)
 
static void UnloadAll ()
 Unload (deregister) all action plugins. More...
 

Static Private Attributes

static std::vector< ACTION_PLUGIN * > m_actionsList
 ACTION_PLUGIN system wide static list. More...
 
static bool m_actionRunning = false
 

Detailed Description

Mainly static.

Storing all plugins information.

Definition at line 115 of file action_plugin.h.

Member Function Documentation

◆ deregister_object()

bool ACTION_PLUGINS::deregister_object ( void *  aObject)
static

Deregister an object which builds a action.

Lookup on the vector calling GetObject until find, then removed and deleted.

Parameters
aObjectis the action plugin object to be deregistered.

Definition at line 189 of file action_plugin.cpp.

190 {
191  int max = GetActionsCount();
192 
193  for( int i = 0; i<max; i++ )
194  {
195  ACTION_PLUGIN* action = GetAction( i );
196 
197  if( action->GetObject() == aObject )
198  {
199  m_actionsList.erase( m_actionsList.begin() + i );
200 
201  //m_actionsListMenu.erase( m_actionsListMenu.begin() + i );
202  delete action;
203  return true;
204  }
205  }
206 
207  return false;
208 }
This is the parent class from where any action plugin class must derive.
Definition: action_plugin.h:38
static int GetActionsCount()
static std::vector< ACTION_PLUGIN * > m_actionsList
ACTION_PLUGIN system wide static list.
static ACTION_PLUGIN * GetAction(const wxString &aName)
virtual void * GetObject()=0
This method gets the pointer to the object from where this action constructs.

References GetAction(), GetActionsCount(), ACTION_PLUGIN::GetObject(), and m_actionsList.

Referenced by PYTHON_ACTION_PLUGINS::deregister_action().

◆ GetAction() [1/2]

ACTION_PLUGIN * ACTION_PLUGINS::GetAction ( const wxString &  aName)
static
Parameters
aNameis the action plugin name.
Returns
a action object by it's name or NULL if it isn't available.

Definition at line 115 of file action_plugin.cpp.

116 {
117  int max = GetActionsCount();
118 
119  for( int i = 0; i<max; i++ )
120  {
121  ACTION_PLUGIN* action = GetAction( i );
122 
123  wxString name = action->GetName();
124 
125  if( name.Cmp( aName )==0 )
126  return action;
127  }
128 
129  return nullptr;
130 }
virtual wxString GetName()=0
This is the parent class from where any action plugin class must derive.
Definition: action_plugin.h:38
static int GetActionsCount()
static ACTION_PLUGIN * GetAction(const wxString &aName)
const char * name
Definition: DXF_plotter.cpp:56

References GetActionsCount(), ACTION_PLUGIN::GetName(), and name.

Referenced by PCB_EDIT_FRAME::buildActionPluginMenus(), deregister_object(), PCB_EDIT_FRAME::GetOrderedActionPlugins(), and register_action().

◆ GetAction() [2/2]

ACTION_PLUGIN * ACTION_PLUGINS::GetAction ( int  aIndex)
static
Parameters
aIndexis the action index in list.
Returns
a action object by it's number or NULL if it isn't available.

Definition at line 55 of file action_plugin.cpp.

56 {
57  return m_actionsList[aIndex];
58 }
static std::vector< ACTION_PLUGIN * > m_actionsList
ACTION_PLUGIN system wide static list.

References m_actionsList.

◆ GetActionByButton()

ACTION_PLUGIN * ACTION_PLUGINS::GetActionByButton ( int  aButton)
static

Find action plugin associated to a button ID.

Parameters
aButtonis the button id (defined with SetActionButton).
Returns
the associated ACTION_PLUGIN (or null if not found).

Definition at line 81 of file action_plugin.cpp.

82 {
83  int max = GetActionsCount();
84 
85  for( int i = 0; i < max; i++ )
86  {
87  if( m_actionsList[i]->m_actionButtonId == aButton )
88  return m_actionsList[i];
89  }
90 
91  return nullptr;
92 }
static int GetActionsCount()
static std::vector< ACTION_PLUGIN * > m_actionsList
ACTION_PLUGIN system wide static list.

References GetActionsCount(), and m_actionsList.

Referenced by PCB_EDIT_FRAME::OnActionPluginButton().

◆ GetActionByMenu()

ACTION_PLUGIN * ACTION_PLUGINS::GetActionByMenu ( int  aMenu)
static

Find action plugin associated to a menu ID.

Parameters
aMenuis the menu id (defined with SetActionMenu).
Returns
the associated ACTION_PLUGIN (or null if not found).

Definition at line 61 of file action_plugin.cpp.

62 {
63  int max = GetActionsCount();
64 
65  for( int i = 0; i < max; i++ )
66  {
67  if( m_actionsList[i]->m_actionMenuId == aMenu )
68  return m_actionsList[i];
69  }
70 
71  return nullptr;
72 }
static int GetActionsCount()
static std::vector< ACTION_PLUGIN * > m_actionsList
ACTION_PLUGIN system wide static list.

References GetActionsCount(), and m_actionsList.

Referenced by PCB_EDIT_FRAME::OnActionPluginMenu().

◆ GetActionByPath()

ACTION_PLUGIN * ACTION_PLUGINS::GetActionByPath ( const wxString &  aPath)
static

Find action plugin by module path.

Parameters
aPathis the path of plugin.
Returns
the corresponding ACTION_PLUGIN (or null if not found).

Definition at line 101 of file action_plugin.cpp.

102 {
103  for( int i = 0; i < GetActionsCount() ; i++ )
104  {
105  if( m_actionsList[i]->GetPluginPath() == aPath)
106  {
107  return m_actionsList[i];
108  }
109  }
110 
111  return nullptr;
112 }
static int GetActionsCount()
static std::vector< ACTION_PLUGIN * > m_actionsList
ACTION_PLUGIN system wide static list.

References GetActionsCount(), and m_actionsList.

◆ GetActionsCount()

int ACTION_PLUGINS::GetActionsCount ( )
static
Returns
the number of actions available into the system.

Definition at line 133 of file action_plugin.cpp.

134 {
135  return m_actionsList.size();
136 }
static std::vector< ACTION_PLUGIN * > m_actionsList
ACTION_PLUGIN system wide static list.

References m_actionsList.

Referenced by PCB_EDIT_FRAME::buildActionPluginMenus(), deregister_object(), GetAction(), GetActionByButton(), GetActionByMenu(), GetActionByPath(), PCB_EDIT_FRAME::GetOrderedActionPlugins(), and register_action().

◆ IsActionRunning()

bool ACTION_PLUGINS::IsActionRunning ( )
static
Returns
true if an action running right now otherwise false.

Definition at line 211 of file action_plugin.cpp.

212 {
214 }
static bool m_actionRunning

References m_actionRunning.

Referenced by IsActionRunning().

◆ register_action()

void ACTION_PLUGINS::register_action ( ACTION_PLUGIN aAction)
static

An action calls this static method when it wants to register itself into the system actions.

Parameters
aActionis the action plugin to be registered.

Definition at line 139 of file action_plugin.cpp.

140 {
141  // Search for this entry do not register twice this action:
142  for( int ii = 0; ii < GetActionsCount(); ii++ )
143  {
144  if( aAction == GetAction( ii ) ) // Already registered
145  return;
146  }
147 
148  // Search for a action with the same name, and remove it if found
149  for( int ii = 0; ii < GetActionsCount(); ii++ )
150  {
151  ACTION_PLUGIN* action = GetAction( ii );
152 
153  if( action->GetName() == aAction->GetName() )
154  {
155  m_actionsList.erase( m_actionsList.begin() + ii );
156 
157  delete action;
158 
159  break;
160  }
161  }
162 
163  wxASSERT( PgmOrNull() ); // PgmOrNull() returning nullptr should never happen,
164  // but it sometimes happens on msys2 build
165 
166  if( PgmOrNull() ) // Hack for msys2. Must be removed when the root cause is fixed
167  {
168  // Load icon if supplied
169  wxString icon_file_name = aAction->GetIconFileName( GetBitmapStore()->IsDarkTheme() );
170 
171  if( !icon_file_name.IsEmpty() )
172  {
173  {
174  wxLogNull eat_errors;
175  aAction->iconBitmap.LoadFile( icon_file_name, wxBITMAP_TYPE_PNG );
176  }
177 
178  if ( !aAction->iconBitmap.IsOk() )
179  {
180  wxLogVerbose( "Failed to load icon " + icon_file_name + " for action plugin " );
181  }
182  }
183  }
184 
185  m_actionsList.push_back( aAction );
186 }
virtual wxString GetName()=0
This is the parent class from where any action plugin class must derive.
Definition: action_plugin.h:38
wxBitmap iconBitmap
bool IsDarkTheme()
Determine if the desktop interface is currently using a dark theme or a light theme.
Definition: gtk/ui.cpp:31
virtual wxString GetIconFileName(bool aDark)=0
PGM_BASE * PgmOrNull()
similar to PGM_BASE& Pgm(), but return a reference that can be nullptr when running a shared lib from...
Definition: cvpcb.cpp:125
static int GetActionsCount()
static std::vector< ACTION_PLUGIN * > m_actionsList
ACTION_PLUGIN system wide static list.
static ACTION_PLUGIN * GetAction(const wxString &aName)
BITMAP_STORE * GetBitmapStore()
Definition: bitmap.cpp:93

References GetAction(), GetActionsCount(), GetBitmapStore(), ACTION_PLUGIN::GetIconFileName(), ACTION_PLUGIN::GetName(), ACTION_PLUGIN::iconBitmap, KIPLATFORM::UI::IsDarkTheme(), m_actionsList, and PgmOrNull().

Referenced by ACTION_PLUGIN::register_action().

◆ SetActionButton()

void ACTION_PLUGINS::SetActionButton ( ACTION_PLUGIN aAction,
int  idButton 
)
static

Associate a button id to an action plugin.

Parameters
aActionis the action.
idButtonis the associated menuitem ID.

Definition at line 95 of file action_plugin.cpp.

96 {
97  aAction->m_actionButtonId = idButton;
98 }

References ACTION_PLUGIN::m_actionButtonId.

Referenced by PCB_EDIT_FRAME::AddActionPluginTools().

◆ SetActionMenu()

void ACTION_PLUGINS::SetActionMenu ( int  aIndex,
int  idMenu 
)
static

Associate a menu id to an action plugin.

Parameters
aIndexis the action index.
idMenuis the associated menuitem ID.

Definition at line 75 of file action_plugin.cpp.

76 {
77  m_actionsList[aIndex]->m_actionMenuId = idMenu;
78 }
static std::vector< ACTION_PLUGIN * > m_actionsList
ACTION_PLUGIN system wide static list.

References m_actionsList.

Referenced by PCB_EDIT_FRAME::buildActionPluginMenus().

◆ SetActionRunning()

void ACTION_PLUGINS::SetActionRunning ( bool  aRunning)
static
Parameters
aRunningsets whether an action is running now.

Definition at line 217 of file action_plugin.cpp.

218 {
220 }
static bool m_actionRunning

References m_actionRunning.

Referenced by PCB_EDIT_FRAME::RunActionPlugin().

◆ UnloadAll()

void ACTION_PLUGINS::UnloadAll ( )
static

Unload (deregister) all action plugins.

Definition at line 223 of file action_plugin.cpp.

224 {
225  for( ACTION_PLUGIN* plugin : m_actionsList )
226  delete plugin;
227 
228  m_actionsList.clear();
229 }
This is the parent class from where any action plugin class must derive.
Definition: action_plugin.h:38
static std::vector< ACTION_PLUGIN * > m_actionsList
ACTION_PLUGIN system wide static list.

References m_actionsList.

Referenced by SCRIPTING_TOOL::reloadPlugins().

Member Data Documentation

◆ m_actionRunning

bool ACTION_PLUGINS::m_actionRunning = false
staticprivate

Definition at line 212 of file action_plugin.h.

Referenced by IsActionRunning(), and SetActionRunning().

◆ m_actionsList

std::vector< ACTION_PLUGIN * > ACTION_PLUGINS::m_actionsList
staticprivate

The documentation for this class was generated from the following files: