46#include "../../scripting/python_scripting.h"
53 Py_XINCREF( aAction );
72 PyObject* pFunc = PyObject_GetAttrString(
m_PyAction, aMethod );
74 if( pFunc && PyCallable_Check( pFunc ) )
76 PyObject* result = PyObject_CallObject( pFunc, aArglist );
81 if( PyErr_Occurred() )
83 wxString message =
_HKI(
"Exception on python action plugin code" );
84 wxString traceback = PyErrStringWithTraceback();
86 std::cerr << message << std::endl << std::endl;
87 std::cerr << traceback << std::endl;
90 wxSafeShowMessage( wxGetTranslation( message ), traceback );
95 wxArrayString messages;
96 messages.Add(
"Fatal error");
97 messages.Add( wxString::Format(
98 "The application handle was destroyed after running Python plugin '%s'.",
105 for(
const wxString& msg : messages )
106 if( (
int)msg.length() > maxLen )
107 maxLen = msg.length();
110 wxString border( ch, 3 );
112 std::cerr << wxString( ch, maxLen + 2 + border.length() * 2 ) << std::endl;
113 std::cerr << border <<
' ' << wxString(
' ', maxLen ) <<
' ' << border << std::endl;
115 for( wxString msg : messages )
116 std::cerr << border <<
' ' << msg.Pad( maxLen - msg.length() ) <<
' ' << border
119 std::cerr << border <<
' ' << wxString(
' ', maxLen ) <<
' ' << border << std::endl;
120 std::cerr << wxString( ch, maxLen + 2 + border.length() * 2 ) << std::endl;
124 std::cerr << std::endl <<
"Press any key to abort..." << std::endl;
125 (void) std::getchar();
139 wxString msg = wxString::Format(
_(
"Method '%s' not found, or not callable" ), aMethod );
140 wxMessageBox( msg,
_(
"Unknown Method" ), wxICON_ERROR | wxOK );
157 PyObject* result =
CallMethod( aMethod, aArglist );
159 ret = PyStringToWx( result );
160 Py_XDECREF( result );
205 PyObject* result =
CallMethod(
"GetShowToolbarButton");
207 return PyObject_IsTrue(result);
215 PyObject* arglist = Py_BuildValue(
"(i)",
static_cast<int>( aDark ) );
219 Py_DECREF( arglist );
284 bool fromEmpty =
false;
289 ITEM_PICKER picker(
nullptr, item, UNDO_REDO::CHANGED );
296 ITEM_PICKER picker(
nullptr, item, UNDO_REDO::CHANGED );
303 ITEM_PICKER picker(
nullptr, item, UNDO_REDO::CHANGED );
310 ITEM_PICKER picker(
nullptr, zone, UNDO_REDO::CHANGED );
325 aActionPlugin->
Run();
338 wxASSERT( oldBuffer );
345 const auto currItemList = currentPcb->
GetItemSet();
348 for(
unsigned int i = 0; i < oldBuffer->
GetCount(); i++ )
351 ITEM_PICKER picker(
nullptr, item, UNDO_REDO::DELETED );
355 if( currItemList.find( item ) == currItemList.end() )
357 deletedItemsList.
PushItem( picker );
364 for(
unsigned int i = 0; i < deletedItemsList.
GetCount(); i++ )
374 ITEM_PICKER picker(
nullptr, item, UNDO_REDO::NEWITEM );
376 commit.
Added( item );
384 ITEM_PICKER picker(
nullptr, item, UNDO_REDO::NEWITEM );
386 commit.
Added( item );
394 ITEM_PICKER picker(
nullptr, item, UNDO_REDO::NEWITEM );
396 commit.
Added( item );
404 ITEM_PICKER picker(
nullptr, zone, UNDO_REDO::NEWITEM );
406 commit.
Added( zone );
440 if( item->IsSelected() && !selection.
Contains( item ) )
442 item->ClearSelected();
443 to_add.push_back( item );
449 if( !item->IsSelected() )
450 to_remove.push_back(
static_cast<BOARD_ITEM*
>( item ) );
453 if( !to_add.empty() )
456 if( !to_remove.empty() )
496 Connect( item->GetId(), wxEVT_COMMAND_MENU_SELECTED,
506 bool need_separator =
true;
509 for(
const auto& entry : orderedPlugins )
512 if( !std::holds_alternative<ACTION_PLUGIN*>( entry ) )
522 need_separator =
false;
533 wxAuiToolBarItem* button =
m_mainToolBar->AddTool( wxID_ANY, wxEmptyString,
536 Connect( button->GetId(), wxEVT_COMMAND_MENU_SELECTED,
551 std::vector<ACTION_PLUGIN*> plugins;
552 std::vector<LEGACY_OR_API_PLUGIN> orderedPlugins;
560 auto loc = std::find_if( plugins.begin(), plugins.end(),
563 return plugin->GetPluginPath() == pair.first;
566 if( loc != plugins.end() )
568 orderedPlugins.push_back( *loc );
569 plugins.erase( loc );
574 for(
auto remaining_plugin : plugins )
575 orderedPlugins.push_back( remaining_plugin );
579 orderedPlugins.push_back( action );
581 return orderedPlugins;
586 bool aPluginDefault )
593 if(
path == aPluginPath )
599 if( identifier == aPluginPath )
604 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...
wxBitmap KiScaledBitmap(BITMAPS aBitmap, wxWindow *aWindow, int aHeight, bool aQuantized)
Construct a wxBitmap from a memory record, scaling it if device DPI demands it.
std::set< BOARD_ITEM *, CompareByUuid > BOARD_ITEM_SET
Set of BOARD_ITEMs ordered by UUID.
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 GetPluginPath()=0
virtual wxString GetName()=0
virtual void Run()=0
This method the the action.
virtual bool GetShowToolbarButton()=0
virtual void Push(const wxString &aMessage=wxEmptyString, 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 ZONES & Zones() const
bool BuildConnectivity(PROGRESS_REPORTER *aReporter=nullptr)
Build or rebuild the board connectivity database for the board, especially the list of connected item...
const FOOTPRINTS & Footprints() const
const BOARD_ITEM_SET GetItemSet()
const TRACKS & Tracks() const
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
const DRAWINGS & Drawings() 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.
static std::vector< const PLUGIN_ACTION * > GetOrderedPluginActions(PLUGIN_ACTION_SCOPE aScope, APP_SETTINGS_BASE *aCfg)
Return ordered list of plugin actions for display in the toolbar Must be static at the moment because...
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< std::variant< ACTION_PLUGIN *, const PLUGIN_ACTION * > > 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.
virtual SETTINGS_MANAGER & GetSettingsManager() const
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
wxString GetClassName() 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
T * GetAppSettings(const wxString &aFilename)
Returns a handle to the a given settings by type If the settings have already been loaded,...
Handle a list of polygons defining a copper zone.
std::vector< EDA_ITEM * > EDA_ITEMS
Define list of drawing items for screens.
KICOMMON_API wxMenuItem * AddMenuItem(wxMenu *aMenu, int aId, const wxString &aText, const wxBitmapBundle &aImage, wxItemKind aType=wxITEM_NORMAL)
Create and insert a menu item with an icon into aMenu.
Class PCBNEW_ACTION_PLUGINS.
PGM_BASE & Pgm()
The global Program "get" accessor.
std::vector< std::pair< wxString, bool > > actions
Ordered list of plugin actions mapped to whether or not they are shown in the toolbar.
An action performed by a plugin via the IPC API (not to be confused with ACTION_PLUGIN,...
VECTOR2< double > VECTOR2D