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 );
 
 
  159    ret = PyStringToWx( 
result );
 
 
  207    return PyObject_IsTrue(
result);
 
 
  215    PyObject* arglist = Py_BuildValue( 
"(i)", 
static_cast<int>( aDark ) );
 
  219    Py_DECREF( arglist );
 
 
  284    bool    fromEmpty   = 
false;
 
  325    aActionPlugin->
Run();
 
  338        wxASSERT( oldBuffer );
 
  345    const auto currItemList = currentPcb->
GetItemSet();
 
  348    for( 
unsigned int i = 0; i < oldBuffer->
GetCount(); i++ )
 
  355        if( currItemList.find( item ) == currItemList.end() )
 
  357            deletedItemsList.
PushItem( picker );
 
  364    for( 
unsigned int i = 0; i < deletedItemsList.
GetCount(); i++ )
 
  376            commit.
Added( item );
 
  386            commit.
Added( item );
 
  396            commit.
Added( item );
 
  406            commit.
Added( zone );
 
 
  440        if( item->IsSelected() && !selection.
Contains( item ) )
 
  442            item->ClearSelected(); 
 
  443            to_add.push_back( item );
 
  449        if( !item->IsSelected() && item->IsBOARD_ITEM() )
 
  450            to_remove.push_back( 
static_cast<BOARD_ITEM*
>( item ) );
 
  453    if( !to_add.empty() )
 
  456    if( !to_remove.empty() )
 
  459    m_pcb->BuildConnectivity();
 
 
  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 = aToolbar->AddTool( wxID_ANY, wxEmptyString,
 
  536            Connect( button->GetId(), wxEVT_COMMAND_MENU_SELECTED,
 
 
  549    std::vector<ACTION_PLUGIN*>       plugins;
 
  550    std::vector<LEGACY_OR_API_PLUGIN> orderedPlugins;
 
  560            auto loc = std::find_if( plugins.begin(), plugins.end(),
 
  563                        return plugin->GetPluginPath() == path;
 
  566            if( loc != plugins.end() )
 
  568                orderedPlugins.push_back( *loc );
 
  569                plugins.erase( loc );
 
  576        orderedPlugins.push_back( remaining_plugin );
 
  580        orderedPlugins.push_back( action );
 
  582    return orderedPlugins;
 
 
  590        for( 
const auto& [
path, visible] : cfg->m_VisibleActionPlugins )
 
  592            if( 
path == aPluginPath )
 
  596        for( 
const auto& [identifier, visible] : cfg->m_Plugins.actions )
 
  598            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
Execute the changes.
 
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 ZONES & Zones() const
 
const FOOTPRINTS & Footprints() const
 
const BOARD_ITEM_SET GetItemSet()
 
const TRACKS & Tracks() const
 
const DRAWINGS & Drawings() const
 
COMMIT & Added(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Notify observers that aItem has been added.
 
COMMIT & Removed(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
 
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.
 
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 addActionPluginTools(ACTION_TOOLBAR *aToolbar)
Append action plugin buttons to given toolbar.
 
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.
 
A holder to handle information on schematic or board items.
 
void PushItem(const ITEM_PICKER &aItem)
Push aItem to the top of the list.
 
const 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
 
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.
 
T * GetAppSettings(const char *aFilename)
 
An action performed by a plugin via the IPC API (not to be confused with ACTION_PLUGIN,...
 
wxString result
Test unit parsing edge cases and error handling.
 
VECTOR2< double > VECTOR2D