41 Py_XINCREF( aAction );
59 PyObject* pFunc = PyObject_GetAttrString(
m_PyAction, aMethod );
61 if( pFunc && PyCallable_Check( pFunc ) )
63 PyObject* result = PyObject_CallObject( pFunc, aArglist );
65 if( PyErr_Occurred() )
68 _(
"Exception on python action plugin code" ),
69 wxICON_ERROR | wxOK );
80 wxString msg =
wxString::Format(
_(
"Method \"%s\" not found, or not callable" ), aMethod );
81 wxMessageBox( msg,
_(
"Unknown Method" ), wxICON_ERROR | wxOK );
98 PyObject* result =
CallMethod( aMethod, aArglist );
101 Py_XDECREF( result );
135 PyObject* result =
CallMethod(
"GetShowToolbarButton");
137 return PyObject_IsTrue(result);
186 #if defined(KICAD_SCRIPTING) && defined(KICAD_SCRIPTING_ACTION_MENU) 188 void PCB_EDIT_FRAME::OnActionPluginMenu( wxCommandEvent& aEvent )
193 RunActionPlugin( actionPlugin );
196 void PCB_EDIT_FRAME::OnActionPluginButton( wxCommandEvent& aEvent )
201 RunActionPlugin( actionPlugin );
204 void PCB_EDIT_FRAME::RunActionPlugin(
ACTION_PLUGIN* aActionPlugin )
209 bool fromEmpty =
false;
248 aActionPlugin->
Run();
261 wxASSERT( oldBuffer );
268 std::set<BOARD_ITEM*> currItemList;
272 currItemList.insert( item );
276 currItemList.insert( item );
280 currItemList.insert( item );
284 currItemList.insert( zone );
287 for(
unsigned int i = 0; i < oldBuffer->
GetCount(); i++ )
294 if( currItemList.find( item ) == currItemList.end() )
295 deletedItemsList.
PushItem( picker );
299 for(
unsigned int i = 0; i < deletedItemsList.
GetCount(); i++ )
355 void PCB_EDIT_FRAME::buildActionPluginMenus(
ACTION_MENU* actionMenu )
368 Connect( item->GetId(), wxEVT_COMMAND_MENU_SELECTED,
369 wxCommandEventHandler( PCB_EDIT_FRAME::OnActionPluginMenu ) );
376 void PCB_EDIT_FRAME::AddActionPluginTools()
378 bool need_separator =
true;
379 const std::vector<ACTION_PLUGIN*>& orderedPlugins = GetOrderedActionPlugins();
388 need_separator =
false;
400 wxID_ANY, wxEmptyString, bitmap, ap->
GetName() );
402 Connect( button->GetId(), wxEVT_COMMAND_MENU_SELECTED,
403 wxCommandEventHandler( PCB_EDIT_FRAME::OnActionPluginButton ) );
412 std::vector<ACTION_PLUGIN*> PCB_EDIT_FRAME::GetOrderedActionPlugins()
414 std::vector<ACTION_PLUGIN*> plugins;
415 std::vector<ACTION_PLUGIN*> orderedPlugins;
421 for(
const auto& pair :
m_settings->m_VisibleActionPlugins )
423 auto loc = std::find_if( plugins.begin(), plugins.end(),
426 return plugin->GetPluginPath() == pair.first;
429 if( loc != plugins.end() )
431 orderedPlugins.push_back( *loc );
432 plugins.erase( loc );
437 for(
auto remaining_plugin : plugins )
438 orderedPlugins.push_back( remaining_plugin );
440 return orderedPlugins;
444 bool PCB_EDIT_FRAME::GetActionPluginButtonVisible(
const wxString& aPluginPath,
bool aPluginDefault )
446 auto& settings =
m_settings->m_VisibleActionPlugins;
448 for(
const auto& entry : settings )
450 if( entry.first == aPluginPath )
455 return aPluginDefault;
virtual wxString GetName()=0
Function GetName.
wxString PyStringToWx(PyObject *aString)
void OnModify() override
Must be called after a board change to set the modified flag.
ACTION_PLUGIN This is the parent class from where any action plugin class must derive.
wxString GetName() override
Function GetName.
wxString CallRetStrMethod(const char *aMethod, PyObject *aArglist=NULL)
void SaveCopyInUndoList(EDA_ITEM *aItemToCopy, UNDO_REDO aTypeCommand) override
Create a new entry in undo list of commands.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
virtual bool GetShowToolbarButton()=0
Function GetShowToolbarButton.
wxMenuItem * AddMenuItem(wxMenu *aMenu, int aId, const wxString &aText, const wxBitmap &aImage, wxItemKind aType=wxITEM_NORMAL)
Create and insert a menu item with an icon into aMenu.
void ActivateGalCanvas() override
Set the #m_Pcb member in such as way as to ensure deleting any previous BOARD.
virtual wxString GetDescription()=0
Function GetDescription.
virtual void PushCommandToUndoList(PICKED_ITEMS_LIST *aItem)
Add a command to undo in the undo list.
void PushItem(const ITEM_PICKER &aItem)
Push aItem to the top of the list.
ACTION_TOOLBAR * m_mainToolBar
const BITMAP_OPAQUE puzzle_piece_xpm[1]
void register_action()
Function register_action It's the standard method of a "ACTION_PLUGIN" to register itself into the AC...
PCBNEW_SETTINGS * m_settings
wxBitmap KiScaledBitmap(BITMAP_DEF aBitmap, wxWindow *aWindow)
Construct a wxBitmap from a memory record, scaling it if device DPI demands it.
unsigned GetCount() const
virtual wxString GetPluginPath()=0
Function GetPluginPath.
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
static void deregister_action(PyObject *aPyAction)
void * GetObject() override
Function GetObject This method gets the pointer to the object from where this action constructs.
wxString GetDescription() override
Function GetDescription.
virtual void Run()=0
Function Run This method the the action.
static ACTION_PLUGIN * GetActionByMenu(int aMenu)
Function GetActionByMenu find action plugin associated to a menu id.
wxString GetPluginPath() override
Function GetPluginPath.
FOOTPRINTS & Footprints()
void Run() override
Function Run This method the the action.
static int GetActionsCount()
Function GetActionsCount.
EDA_ITEM * GetPickedItem(unsigned int aIdx) const
virtual PICKED_ITEMS_LIST * PopCommandFromUndoList()
Return the last command to undo and remove it from list, nothing is deleted.
ZONE handles a list of polygons defining a copper zone.
PYTHON_ACTION_PLUGIN(PyObject *action)
wxString GetIconFileName() override
Function GetIconFileName.
A holder to handle information on schematic or board items.
bool GetShowToolbarButton() override
Function GetShowToolbarButton.
PyObject * CallMethod(const char *aMethod, PyObject *aArglist=NULL)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
ITEM_PICKER GetItemWrapper(unsigned int aIdx) const
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.
Information pertinent to a Pcbnew printed circuit board.
static void SetActionMenu(int aIndex, int idMenu)
Function SetActionMenu Associate a menu id to an action plugin.
Class PCBNEW_ACTION_PLUGINS.
wxString PyErrStringWithTraceback()
void ClearItemsList()
Delete only the list of pickers NOT the picked data itself.
bool ContainsItem(const EDA_ITEM *aItem) const
static void register_action(PyObject *aPyAction)
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.
wxString GetCategoryName() override
Function GetCategoryName.