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  int max = GetActionsCount();
79 
80  for( int i = 0; i < max; i++ )
81  {
82  if( m_actionsList[i]->m_actionButtonId == aButton )
83  return m_actionsList[i];
84  }
85 
86  return NULL;
87 }
88 
89 
90 void ACTION_PLUGINS::SetActionButton( ACTION_PLUGIN* aAction, int idButton )
91 {
92  aAction->m_actionButtonId = idButton;
93 }
94 
95 
97 {
98  for( int i = 0; i < GetActionsCount() ; i++ )
99  {
100  if( m_actionsList[i]->GetPluginPath() == aPath)
101  {
102  return m_actionsList[i];
103  }
104  }
105 
106  return NULL;
107 }
108 
109 
110 ACTION_PLUGIN* ACTION_PLUGINS::GetAction( const wxString& aName )
111 {
112  int max = GetActionsCount();
113 
114  for( int i = 0; i<max; i++ )
115  {
116  ACTION_PLUGIN* action = GetAction( i );
117 
118  wxString name = action->GetName();
119 
120  if( name.Cmp( aName )==0 )
121  return action;
122  }
123 
124  return NULL;
125 }
126 
127 
129 {
130  return m_actionsList.size();
131 }
132 
133 
135 {
136  // Search for this entry do not register twice this action:
137  for( int ii = 0; ii < GetActionsCount(); ii++ )
138  {
139  if( aAction == GetAction( ii ) ) // Already registered
140  return;
141  }
142 
143  // Search for a action with the same name, and remove it if found
144  for( int ii = 0; ii < GetActionsCount(); ii++ )
145  {
146  ACTION_PLUGIN* action = GetAction( ii );
147 
148  if( action->GetName() == aAction->GetName() )
149  {
150  m_actionsList.erase( m_actionsList.begin() + ii );
151 
152  delete action;
153 
154  break;
155  }
156  }
157 
158  // Load icon if supplied
159  if (!aAction->GetIconFileName().IsEmpty())
160  {
161  {
162  wxLogNull eat_errors;
163  aAction->iconBitmap.LoadFile( aAction->GetIconFileName() , wxBITMAP_TYPE_PNG );
164  }
165 
166  if ( !aAction->iconBitmap.IsOk() )
167  {
168  wxLogVerbose( "Failed to load icon " + aAction->GetIconFileName() + " for action plugin " );
169  }
170  }
171 
172  m_actionsList.push_back( aAction );
173 }
174 
175 
177 {
178  int max = GetActionsCount();
179 
180  for( int i = 0; i<max; i++ )
181  {
182  ACTION_PLUGIN* action = GetAction( i );
183 
184  if( action->GetObject() == aObject )
185  {
186  m_actionsList.erase( m_actionsList.begin() + i );
187  //m_actionsListMenu.erase( m_actionsListMenu.begin() + i );
188  delete action;
189  return true;
190  }
191  }
192 
193  return false;
194 }
195 
196 
198 {
200 }
201 
202 
203 void ACTION_PLUGINS::SetActionRunning( bool aRunning )
204 {
206 }
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 ACTION_PLUGIN * GetActionByPath(const wxString &aPath)
Function GetActionByPath find action plugin by module path.
wxBitmap iconBitmap
Definition: action_plugin.h:50
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()
virtual wxString GetPluginPath()=0
Function GetPluginPath.
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 void SetActionButton(ACTION_PLUGIN *aAction, int idButton)
Function SetActionButton Associate a button id to an action plugin.
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.
virtual wxString GetIconFileName()=0
Function GetIconFileName.
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 ACTION_PLUGIN * GetActionByButton(int aButton)
Function GetActionByButton find action plugin associated to a button id.
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...