44#include "../../scripting/python_scripting.h"
51 Py_XINCREF( aAction );
70 PyObject* pFunc = PyObject_GetAttrString(
m_PyAction, aMethod );
72 if( pFunc && PyCallable_Check( pFunc ) )
74 PyObject* result = PyObject_CallObject( pFunc, aArglist );
76 if( PyErr_Occurred() )
78 wxMessageBox( PyErrStringWithTraceback(),
79 _(
"Exception on python action plugin code" ),
80 wxICON_ERROR | wxOK );
91 wxString msg = wxString::Format(
_(
"Method '%s' not found, or not callable" ), aMethod );
92 wxMessageBox( msg,
_(
"Unknown Method" ), wxICON_ERROR | wxOK );
109 PyObject* result =
CallMethod( aMethod, aArglist );
111 ret = PyStringToWx( result );
112 Py_XDECREF( result );
146 PyObject* result =
CallMethod(
"GetShowToolbarButton");
148 return PyObject_IsTrue(result);
156 PyObject* arglist = Py_BuildValue(
"(i)",
static_cast<int>( aDark ) );
160 Py_DECREF( arglist );
225 bool fromEmpty =
false;
230 ITEM_PICKER picker(
nullptr, item, UNDO_REDO::CHANGED );
237 ITEM_PICKER picker(
nullptr, item, UNDO_REDO::CHANGED );
244 ITEM_PICKER picker(
nullptr, item, UNDO_REDO::CHANGED );
251 ITEM_PICKER picker(
nullptr, zone, UNDO_REDO::CHANGED );
266 aActionPlugin->
Run();
279 wxASSERT( oldBuffer );
286 const std::set<BOARD_ITEM*> currItemList = currentPcb->
GetItemSet();
289 for(
unsigned int i = 0; i < oldBuffer->
GetCount(); i++ )
292 ITEM_PICKER picker(
nullptr, item, UNDO_REDO::DELETED );
296 if( currItemList.find( item ) == currItemList.end() )
298 deletedItemsList.
PushItem( picker );
305 for(
unsigned int i = 0; i < deletedItemsList.
GetCount(); i++ )
315 ITEM_PICKER picker(
nullptr, item, UNDO_REDO::NEWITEM );
317 commit.
Added( item );
325 ITEM_PICKER picker(
nullptr, item, UNDO_REDO::NEWITEM );
327 commit.
Added( item );
335 ITEM_PICKER picker(
nullptr, item, UNDO_REDO::NEWITEM );
337 commit.
Added( item );
345 ITEM_PICKER picker(
nullptr, zone, UNDO_REDO::NEWITEM );
347 commit.
Added( zone );
381 if( item->IsSelected() && !selection.
Contains( item ) )
383 item->ClearSelected();
384 to_add.push_back( item );
390 if( !item->IsSelected() )
391 to_remove.push_back(
static_cast<BOARD_ITEM*
>( item ) );
394 if( !to_add.empty() )
397 if( !to_remove.empty() )
436 Connect( item->GetId(), wxEVT_COMMAND_MENU_SELECTED,
446 bool need_separator =
true;
456 need_separator =
false;
462 if ( ap->iconBitmap.IsOk() )
467 wxAuiToolBarItem* button =
m_mainToolBar->AddTool( wxID_ANY, wxEmptyString,
468 bitmap, ap->GetName() );
470 Connect( button->GetId(), wxEVT_COMMAND_MENU_SELECTED,
484 std::vector<ACTION_PLUGIN*> plugins;
485 std::vector<ACTION_PLUGIN*> orderedPlugins;
493 auto loc = std::find_if( plugins.begin(), plugins.end(),
496 return plugin->GetPluginPath() == pair.first;
499 if( loc != plugins.end() )
501 orderedPlugins.push_back( *loc );
502 plugins.erase( loc );
507 for(
auto remaining_plugin : plugins )
508 orderedPlugins.push_back( remaining_plugin );
510 return orderedPlugins;
515 bool aPluginDefault )
521 if( entry.first == aPluginPath )
526 return aPluginDefault;
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
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.
wxBitmap KiScaledBitmap(BITMAPS aBitmap, wxWindow *aWindow, int aHeight, bool aQuantized)
Construct a wxBitmap from a memory record, scaling it if device DPI demands it.
static bool deregister_object(void *aObject)
Deregister an object which builds a action.
static ACTION_PLUGIN * GetActionByMenu(int aMenu)
Find action plugin associated to a menu ID.
static int GetActionsCount()
static ACTION_PLUGIN * GetAction(const wxString &aName)
static void SetActionButton(ACTION_PLUGIN *aAction, int idButton)
Associate a button id to an action plugin.
static void SetActionMenu(int aIndex, int idMenu)
Associate a menu id to an action plugin.
static void SetActionRunning(bool aRunning)
static ACTION_PLUGIN * GetActionByButton(int aButton)
Find action plugin associated to a button ID.
This is the parent class from where any action plugin class must derive.
void register_action()
It's the standard method of a "ACTION_PLUGIN" to register itself into the ACTION_PLUGINS singleton ma...
virtual wxString GetDescription()=0
virtual wxString GetName()=0
virtual void Run()=0
This method the the action.
virtual void Push(const wxString &aMessage=wxT("A commit"), int aCommitFlags=0) override
Revert the commit by restoring the modified items state.
const VECTOR2I & GetGridOrigin()
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Information pertinent to a Pcbnew printed circuit board.
const PAGE_INFO & GetPageSettings() const
const std::set< BOARD_ITEM * > GetItemSet()
bool BuildConnectivity(PROGRESS_REPORTER *aReporter=nullptr)
Build or rebuild the board connectivity database for the board, especially the list of connected item...
FOOTPRINTS & Footprints()
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
COMMIT & Added(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Remove a new item from the model.
COMMIT & Removed(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Modify a given item in the model.
virtual void PushCommandToUndoList(PICKED_ITEMS_LIST *aItem)
Add a command to undo in the undo list.
virtual PICKED_ITEMS_LIST * PopCommandFromUndoList()
Return the last command to undo and remove it from list, nothing is deleted.
ACTION_TOOLBAR * m_mainToolBar
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
KIGFX::GAL * GetGAL() const
Return a pointer to the GAL instance used in the panel.
A base class for most all the KiCad significant classes used in schematics and boards.
void SetGridOrigin(const VECTOR2D &aGridOrigin)
Set the origin point for the grid.
void Clear()
Remove all items from the view.
ACTION_PLUGIN_SETTINGS_LIST m_VisibleActionPlugins
void SaveCopyInUndoList(EDA_ITEM *aItemToCopy, UNDO_REDO aTypeCommand) override
Create a new entry in undo list of commands.
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
virtual KIGFX::PCB_VIEW * GetView() const override
Return a pointer to the #VIEW instance used in the panel.
void DisplayBoard(BOARD *aBoard, PROGRESS_REPORTER *aReporter=nullptr)
Add all items from the current board to the VIEW, so they can be displayed by GAL.
void SyncLayersVisibility(const BOARD *aBoard)
Update "visibility" property of each layer of a given BOARD.
void OnModify() override
Must be called after a board change to set the modified flag.
static std::vector< ACTION_PLUGIN * > GetOrderedActionPlugins()
Return ordered list of plugins in sequence in which they should appear on toolbar or in settings.
void SetPageSettings(const PAGE_INFO &aPageSettings) override
void OnActionPluginButton(wxCommandEvent &aEvent)
Launched by the button when an action is called.
void RunActionPlugin(ACTION_PLUGIN *aActionPlugin)
Execute action plugin's Run() method and updates undo buffer.
void buildActionPluginMenus(ACTION_MENU *aActionMenu)
Fill action menu with all registered action plugins.
void RebuildAndRefresh()
Rebuilds board connectivity, refreshes canvas.
static bool GetActionPluginButtonVisible(const wxString &aPluginPath, bool aPluginDefault)
Return true if button visibility action plugin setting was set to true or it is unset and plugin defa...
SELECTION & GetCurrentSelection() override
Get the current selection from the canvas area.
void OnActionPluginMenu(wxCommandEvent &aEvent)
Launched by the menu when an action is called.
void AddActionPluginTools()
Append action plugin buttons to main toolbar.
A holder to handle information on schematic or board items.
void PushItem(const ITEM_PICKER &aItem)
Push aItem to the top of the list.
ITEM_PICKER GetItemWrapper(unsigned int aIdx) const
bool ContainsItem(const EDA_ITEM *aItem) const
unsigned GetCount() const
void ClearItemsList()
Delete only the list of pickers NOT the picked data itself.
EDA_ITEM * GetPickedItem(unsigned int aIdx) const
static void deregister_action(PyObject *aPyAction)
static void register_action(PyObject *aPyAction)
bool GetShowToolbarButton() override
wxString CallRetStrMethod(const char *aMethod, PyObject *aArglist=nullptr)
PyObject * CallMethod(const char *aMethod, PyObject *aArglist=nullptr)
wxString GetCategoryName() override
wxString GetName() override
wxString GetDescription() override
wxString GetPluginPath() override
PYTHON_ACTION_PLUGIN(PyObject *action)
void Run() override
This method the the action.
wxString GetIconFileName(bool aDark) override
void * GetObject() override
This method gets the pointer to the object from where this action constructs.
const std::deque< EDA_ITEM * > GetItems() const
bool Contains(EDA_ITEM *aItem) const
Handle a list of polygons defining a copper zone.
std::vector< EDA_ITEM * > EDA_ITEMS
Define list of drawing items for screens.
Class PCBNEW_ACTION_PLUGINS.
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
VECTOR2< double > VECTOR2D