KiCad PCB EDA Suite
class_action_plugin.cpp
Go to the documentation of this file.
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 
30 #include "class_action_plugin.h"
31 
32 
34 {
35 }
36 
37 
39 {
41 }
42 
43 
44 std::vector<ACTION_PLUGIN*> ACTION_PLUGINS::m_actionsList;
45 
46 
48 {
49  return m_actionsList[aIndex];
50 }
51 
52 
54 {
55  int max = GetActionsCount();
56 
57  for( int i = 0; i < max; i++ )
58  {
59  if( m_actionsList[i]->m_actionMenuId == aMenu )
60  return m_actionsList[i];
61  }
62 
63  return NULL;
64 }
65 
66 
67 void ACTION_PLUGINS::SetActionMenu( int aIndex, int idMenu )
68 {
69  m_actionsList[aIndex]->m_actionMenuId = idMenu;
70 }
71 
72 
74 {
75  return m_actionsList[aIndex]->m_actionMenuId;
76 }
77 
78 
80 {
81  int max = GetActionsCount();
82 
83  for( int i = 0; i<max; i++ )
84  {
85  ACTION_PLUGIN* action = GetAction( i );
86 
87  wxString name = action->GetName();
88 
89  if( name.Cmp( aName )==0 )
90  return action;
91  }
92 
93  return NULL;
94 }
95 
96 
98 {
99  return m_actionsList.size();
100 }
101 
102 
104 {
105  // Search for this entry do not register twice this action:
106  for( int ii = 0; ii < GetActionsCount(); ii++ )
107  {
108  if( aAction == GetAction( ii ) ) // Already registered
109  return;
110  }
111 
112  // Search for a action with the same name, and remove it if found
113  for( int ii = 0; ii < GetActionsCount(); ii++ )
114  {
115  ACTION_PLUGIN* action = GetAction( ii );
116 
117  if( action->GetName() == aAction->GetName() )
118  {
119  m_actionsList.erase( m_actionsList.begin() + ii );
120 
121  delete action;
122 
123  break;
124  }
125  }
126 
127  m_actionsList.push_back( aAction );
128 }
129 
130 
132 {
133  int max = GetActionsCount();
134 
135  for( int i = 0; i<max; i++ )
136  {
137  ACTION_PLUGIN* action = GetAction( i );
138 
139  if( action->GetObject() == aObject )
140  {
141  m_actionsList.erase( m_actionsList.begin() + i );
142  //m_actionsListMenu.erase( m_actionsListMenu.begin() + i );
143  delete action;
144  return true;
145  }
146  }
147 
148  return false;
149 }
virtual wxString GetName()=0
Function GetName.
Class ACTION_PLUGIN This is the parent class from where any action plugin class must derive...
static ACTION_PLUGIN * GetAction(wxString aName)
Function GetAction.
static int GetActionMenu(int aIndex)
Function GetActionMenu Provide menu id for a plugin index.
void register_action()
Function register_action It's the standard method of a "ACTION_PLUGIN" to register itself into the AC...
Class PCBNEW_ACTION_PLUGINS.
static ACTION_PLUGIN * GetActionByMenu(int aMenu)
Function GetActionByMenu find action plugin associated to a menu id.
static int GetActionsCount()
Function GetActionsCount.
static void register_action(ACTION_PLUGIN *aAction)
Function register_action An action calls this static method when it wants to register itself into the...
static std::vector< ACTION_PLUGIN * > m_actionsList
ACTION_PLUGIN system wide static list.
#define max(a, b)
Definition: auxiliary.h:86
static void SetActionMenu(int aIndex, int idMenu)
Function SetActionMenu Associate a menu id to an action plugin.
const char * name
static bool deregister_object(void *aObject)
Function deregister_object Anyone calls this method to deregister an object which builds a action...
virtual void * GetObject()=0
Function GetObject This method gets the pointer to the object from where this action constructs...