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 );
197 PyObject* result =
CallMethod(
"GetShowToolbarButton");
199 return PyObject_IsTrue(result);
207 PyObject* arglist = Py_BuildValue(
"(i)",
static_cast<int>( aDark ) );
211 Py_DECREF( arglist );
276 bool fromEmpty =
false;
281 ITEM_PICKER picker(
nullptr, item, UNDO_REDO::CHANGED );
288 ITEM_PICKER picker(
nullptr, item, UNDO_REDO::CHANGED );
295 ITEM_PICKER picker(
nullptr, item, UNDO_REDO::CHANGED );
302 ITEM_PICKER picker(
nullptr, zone, UNDO_REDO::CHANGED );
317 aActionPlugin->
Run();
330 wxASSERT( oldBuffer );
337 const std::set<BOARD_ITEM*> currItemList = currentPcb->
GetItemSet();
340 for(
unsigned int i = 0; i < oldBuffer->
GetCount(); i++ )
343 ITEM_PICKER picker(
nullptr, item, UNDO_REDO::DELETED );
347 if( currItemList.find( item ) == currItemList.end() )
349 deletedItemsList.
PushItem( picker );
356 for(
unsigned int i = 0; i < deletedItemsList.
GetCount(); i++ )
366 ITEM_PICKER picker(
nullptr, item, UNDO_REDO::NEWITEM );
368 commit.
Added( item );
376 ITEM_PICKER picker(
nullptr, item, UNDO_REDO::NEWITEM );
378 commit.
Added( item );
386 ITEM_PICKER picker(
nullptr, item, UNDO_REDO::NEWITEM );
388 commit.
Added( item );
396 ITEM_PICKER picker(
nullptr, zone, UNDO_REDO::NEWITEM );
398 commit.
Added( zone );
432 if( item->IsSelected() && !selection.
Contains( item ) )
434 item->ClearSelected();
435 to_add.push_back( item );
441 if( !item->IsSelected() )
442 to_remove.push_back(
static_cast<BOARD_ITEM*
>( item ) );
445 if( !to_add.empty() )
448 if( !to_remove.empty() )
487 Connect( item->GetId(), wxEVT_COMMAND_MENU_SELECTED,
497 bool need_separator =
true;
507 need_separator =
false;
513 if ( ap->iconBitmap.IsOk() )
518 wxAuiToolBarItem* button =
m_mainToolBar->AddTool( wxID_ANY, wxEmptyString,
519 bitmap, ap->GetName() );
521 Connect( button->GetId(), wxEVT_COMMAND_MENU_SELECTED,
535 std::vector<ACTION_PLUGIN*> plugins;
536 std::vector<ACTION_PLUGIN*> orderedPlugins;
544 auto loc = std::find_if( plugins.begin(), plugins.end(),
547 return plugin->GetPluginPath() == pair.first;
550 if( loc != plugins.end() )
552 orderedPlugins.push_back( *loc );
553 plugins.erase( loc );
558 for(
auto remaining_plugin : plugins )
559 orderedPlugins.push_back( remaining_plugin );
561 return orderedPlugins;
566 bool aPluginDefault )
572 if( entry.first == aPluginPath )
577 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