KiCad PCB EDA Suite
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 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 
30 #include "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 
51 {
52  return m_actionsList[aIndex];
53 }
54 
55 
57 {
58  int max = GetActionsCount();
59 
60  for( int i = 0; i < max; i++ )
61  {
62  if( m_actionsList[i]->m_actionMenuId == aMenu )
63  return m_actionsList[i];
64  }
65 
66  return NULL;
67 }
68 
69 
70 void ACTION_PLUGINS::SetActionMenu( int aIndex, int idMenu )
71 {
72  m_actionsList[aIndex]->m_actionMenuId = idMenu;
73 }
74 
75 
77 {
78  return m_actionsList[aIndex]->m_actionMenuId;
79 }
80 
81 
82 ACTION_PLUGIN* ACTION_PLUGINS::GetAction( const wxString& aName )
83 {
84  int max = GetActionsCount();
85 
86  for( int i = 0; i<max; i++ )
87  {
88  ACTION_PLUGIN* action = GetAction( i );
89 
90  wxString name = action->GetName();
91 
92  if( name.Cmp( aName )==0 )
93  return action;
94  }
95 
96  return NULL;
97 }
98 
99 
101 {
102  return m_actionsList.size();
103 }
104 
105 
107 {
108  // Search for this entry do not register twice this action:
109  for( int ii = 0; ii < GetActionsCount(); ii++ )
110  {
111  if( aAction == GetAction( ii ) ) // Already registered
112  return;
113  }
114 
115  // Search for a action with the same name, and remove it if found
116  for( int ii = 0; ii < GetActionsCount(); ii++ )
117  {
118  ACTION_PLUGIN* action = GetAction( ii );
119 
120  if( action->GetName() == aAction->GetName() )
121  {
122  m_actionsList.erase( m_actionsList.begin() + ii );
123 
124  delete action;
125 
126  break;
127  }
128  }
129 
130  m_actionsList.push_back( aAction );
131 }
132 
133 
135 {
136  int max = GetActionsCount();
137 
138  for( int i = 0; i<max; i++ )
139  {
140  ACTION_PLUGIN* action = GetAction( i );
141 
142  if( action->GetObject() == aObject )
143  {
144  m_actionsList.erase( m_actionsList.begin() + i );
145  //m_actionsListMenu.erase( m_actionsListMenu.begin() + i );
146  delete action;
147  return true;
148  }
149  }
150 
151  return false;
152 }
153 
154 
156 {
158 }
159 
160 
161 void ACTION_PLUGINS::SetActionRunning( bool aRunning )
162 {
164 }
virtual wxString GetName()=0
Function GetName.
Class ACTION_PLUGIN This is the parent class from where any action plugin class must derive...
Definition: action_plugin.h:40
static bool m_actionRunning
static bool IsActionRunning()
Function IsActionRunning.
static int GetActionMenu(int aIndex)
Function GetActionMenu Provide menu id for a plugin index.
void register_action()
Function register_action It&#39;s the standard method of a "ACTION_PLUGIN" to register itself into the AC...
virtual ~ACTION_PLUGIN()
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.
static ACTION_PLUGIN * GetAction(const wxString &aName)
Function GetAction.
Class PCBNEW_ACTION_PLUGINS.
const char * name
Definition: DXF_plotter.cpp:61
#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.
size_t i
Definition: json11.cpp:597
static bool deregister_object(void *aObject)
Function deregister_object Anyone calls this method to deregister an object which builds a action...
static void SetActionRunning(bool aRunning)
Function SetActionRunning.
virtual void * GetObject()=0
Function GetObject This method gets the pointer to the object from where this action constructs...