KiCad PCB EDA Suite
PANEL_PCBNEW_ACTION_PLUGINS Class Reference

#include <panel_pcbnew_action_plugins.h>

Inheritance diagram for PANEL_PCBNEW_ACTION_PLUGINS:
PANEL_PCBNEW_ACTION_PLUGINS_BASE

Public Member Functions

 PANEL_PCBNEW_ACTION_PLUGINS (PCB_EDIT_FRAME *aFrame, PAGED_DIALOG *aWindow)
 
bool TransferDataFromWindow () override
 
bool TransferDataToWindow () override
 
 ~PANEL_PCBNEW_ACTION_PLUGINS () override
 
void OnGridCellClick (wxGridEvent &event) override
 Selects a whole row. More...
 
void OnMoveUpButtonClick (wxCommandEvent &event) override
 Moves plugin up in the grid. More...
 
void OnMoveDownButtonClick (wxCommandEvent &event) override
 Moves plugin down in the grid. More...
 
void OnOpenDirectoryButtonClick (wxCommandEvent &event) override
 Opens user's action plugin directory. More...
 
void OnReloadButtonClick (wxCommandEvent &event) override
 Reloads plugins and updates grid. More...
 
void OnShowErrorsButtonClick (wxCommandEvent &event) override
 Shows plugin import errors. More...
 

Protected Attributes

WX_GRIDm_grid
 
wxBitmapButton * m_moveUpButton
 
wxBitmapButton * m_moveDownButton
 
wxBitmapButton * m_openDirectoryButton
 
wxBitmapButton * m_reloadButton
 
wxBitmapButton * m_showErrorsButton
 

Private Types

enum  GRID_COLUMNS {
  COLUMN_ICON, COLUMN_VISIBLE, COLUMN_NAME, COLUMN_CATEGORY,
  COLUMN_DESCRIPTION, COLUMN_PATH
}
 

Private Member Functions

void SwapRows (int aRowA, int aRowB)
 
void SelectRow (int aRow)
 

Private Attributes

PCB_EDIT_FRAMEm_frame
 
wxBitmap m_genericIcon
 

Detailed Description

Definition at line 23 of file panel_pcbnew_action_plugins.h.

Member Enumeration Documentation

◆ GRID_COLUMNS

Constructor & Destructor Documentation

◆ PANEL_PCBNEW_ACTION_PLUGINS()

PANEL_PCBNEW_ACTION_PLUGINS::PANEL_PCBNEW_ACTION_PLUGINS ( PCB_EDIT_FRAME aFrame,
PAGED_DIALOG aWindow 
)

Definition at line 41 of file panel_pcbnew_action_plugins.cpp.

42  :
44  m_frame( aFrame )
45 {
47  m_grid->PushEventHandler( new GRID_TRICKS( m_grid ) );
48 
49  m_moveUpButton->SetBitmap( KiBitmap( BITMAPS::small_up ) );
54 }
Add mouse and command handling (such as cut, copy, and paste) to a WX_GRID instance.
Definition: grid_tricks.h:55
PANEL_PCBNEW_ACTION_PLUGINS_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxTAB_TRAVERSAL, const wxString &name=wxEmptyString)
wxTreebook * GetTreebook()
Definition: paged_dialog.h:37
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
Definition: bitmap.cpp:105

References KiBitmap(), m_genericIcon, PANEL_PCBNEW_ACTION_PLUGINS_BASE::m_grid, PANEL_PCBNEW_ACTION_PLUGINS_BASE::m_moveDownButton, PANEL_PCBNEW_ACTION_PLUGINS_BASE::m_moveUpButton, PANEL_PCBNEW_ACTION_PLUGINS_BASE::m_openDirectoryButton, PANEL_PCBNEW_ACTION_PLUGINS_BASE::m_reloadButton, PANEL_PCBNEW_ACTION_PLUGINS_BASE::m_showErrorsButton, puzzle_piece, small_down, small_folder, small_refresh, small_up, and small_warning.

◆ ~PANEL_PCBNEW_ACTION_PLUGINS()

PANEL_PCBNEW_ACTION_PLUGINS::~PANEL_PCBNEW_ACTION_PLUGINS ( )
override

Definition at line 57 of file panel_pcbnew_action_plugins.cpp.

58 {
59  m_grid->PopEventHandler( true );
60 }

References PANEL_PCBNEW_ACTION_PLUGINS_BASE::m_grid.

Member Function Documentation

◆ OnGridCellClick()

void PANEL_PCBNEW_ACTION_PLUGINS::OnGridCellClick ( wxGridEvent &  event)
overridevirtual

Selects a whole row.

Reimplemented from PANEL_PCBNEW_ACTION_PLUGINS_BASE.

Definition at line 63 of file panel_pcbnew_action_plugins.cpp.

64 {
65  SelectRow( event.GetRow() );
66 }

References SelectRow().

◆ OnMoveDownButtonClick()

void PANEL_PCBNEW_ACTION_PLUGINS::OnMoveDownButtonClick ( wxCommandEvent &  event)
overridevirtual

Moves plugin down in the grid.

Reimplemented from PANEL_PCBNEW_ACTION_PLUGINS_BASE.

Definition at line 98 of file panel_pcbnew_action_plugins.cpp.

99 {
100  auto selectedRows = m_grid->GetSelectedRows();
101 
102  // If nothing is selected or multiple rows are selected don't do anything.
103  if( selectedRows.size() != 1 ) return;
104 
105  int selectedRow = selectedRows[0];
106 
107  // If last row is selected, then it can't go any further down.
108  if( selectedRow + 1 == m_grid->GetNumberRows() )
109  {
110  wxBell();
111  return;
112  }
113 
114  SwapRows( selectedRow, selectedRow + 1 );
115 
116  SelectRow( selectedRow + 1 );
117 }

References PANEL_PCBNEW_ACTION_PLUGINS_BASE::m_grid, SelectRow(), and SwapRows().

◆ OnMoveUpButtonClick()

void PANEL_PCBNEW_ACTION_PLUGINS::OnMoveUpButtonClick ( wxCommandEvent &  event)
overridevirtual

Moves plugin up in the grid.

Reimplemented from PANEL_PCBNEW_ACTION_PLUGINS_BASE.

Definition at line 76 of file panel_pcbnew_action_plugins.cpp.

77 {
78  auto selectedRows = m_grid->GetSelectedRows();
79 
80  // If nothing is selected or multiple rows are selected don't do anything.
81  if( selectedRows.size() != 1 ) return;
82 
83  int selectedRow = selectedRows[0];
84 
85  // If first row is selected, then it can't go any further up.
86  if( selectedRow == 0 )
87  {
88  wxBell();
89  return;
90  }
91 
92  SwapRows( selectedRow, selectedRow - 1 );
93 
94  SelectRow( selectedRow - 1 );
95 }

References PANEL_PCBNEW_ACTION_PLUGINS_BASE::m_grid, SelectRow(), and SwapRows().

◆ OnOpenDirectoryButtonClick()

void PANEL_PCBNEW_ACTION_PLUGINS::OnOpenDirectoryButtonClick ( wxCommandEvent &  event)
overridevirtual

Opens user's action plugin directory.

Reimplemented from PANEL_PCBNEW_ACTION_PLUGINS_BASE.

Definition at line 235 of file panel_pcbnew_action_plugins.cpp.

236 {
238 }
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:143
static TOOL_ACTION pluginsShowFolder
Definition: pcb_actions.h:313
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:54

References TOOLS_HOLDER::GetToolManager(), m_frame, PCB_ACTIONS::pluginsShowFolder, and TOOL_MANAGER::RunAction().

◆ OnReloadButtonClick()

void PANEL_PCBNEW_ACTION_PLUGINS::OnReloadButtonClick ( wxCommandEvent &  event)
overridevirtual

Reloads plugins and updates grid.

Reimplemented from PANEL_PCBNEW_ACTION_PLUGINS_BASE.

Definition at line 143 of file panel_pcbnew_action_plugins.cpp.

144 {
147 }
static TOOL_ACTION pluginsReload
Scripting Actions.
Definition: pcb_actions.h:312
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:143
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:54

References TOOLS_HOLDER::GetToolManager(), m_frame, PCB_ACTIONS::pluginsReload, TOOL_MANAGER::RunAction(), and TransferDataToWindow().

◆ OnShowErrorsButtonClick()

void PANEL_PCBNEW_ACTION_PLUGINS::OnShowErrorsButtonClick ( wxCommandEvent &  event)
overridevirtual

Shows plugin import errors.

Reimplemented from PANEL_PCBNEW_ACTION_PLUGINS_BASE.

Definition at line 240 of file panel_pcbnew_action_plugins.cpp.

241 {
242  wxString trace;
243  pcbnewGetWizardsBackTrace( trace );
244 
245  // Now display the filtered trace in our dialog
246  // (a simple wxMessageBox is really not suitable for long messages)
247  DIALOG_FOOTPRINT_WIZARD_LOG logWindow( this );
248  logWindow.m_Message->SetValue( trace );
249  logWindow.ShowModal();
250 }
Class DIALOG_FOOTPRINT_WIZARD_LOG.
void pcbnewGetWizardsBackTrace(wxString &aTrace)
Return the backtrace of errors (if any) when wizard python scripts are loaded.

References DIALOG_FOOTPRINT_WIZARD_LOG::m_Message, and pcbnewGetWizardsBackTrace().

◆ SelectRow()

void PANEL_PCBNEW_ACTION_PLUGINS::SelectRow ( int  aRow)
private

Definition at line 69 of file panel_pcbnew_action_plugins.cpp.

70 {
71  m_grid->ClearSelection();
72  m_grid->SelectRow( aRow );
73 }

References PANEL_PCBNEW_ACTION_PLUGINS_BASE::m_grid.

Referenced by OnGridCellClick(), OnMoveDownButtonClick(), and OnMoveUpButtonClick().

◆ SwapRows()

void PANEL_PCBNEW_ACTION_PLUGINS::SwapRows ( int  aRowA,
int  aRowB 
)
private

Definition at line 120 of file panel_pcbnew_action_plugins.cpp.

121 {
122  m_grid->Freeze();
123 
124  // Swap all columns except icon
125  wxString tempStr;
126 
127  for( int column = 1; column < m_grid->GetNumberCols(); column++ )
128  {
129  tempStr = m_grid->GetCellValue( aRowA, column );
130  m_grid->SetCellValue( aRowA, column, m_grid->GetCellValue( aRowB, column ) );
131  m_grid->SetCellValue( aRowB, column, tempStr );
132  }
133 
134  // Swap icon column renderers
135  auto cellRenderer = m_grid->GetCellRenderer( aRowA, COLUMN_ICON );
136  m_grid->SetCellRenderer( aRowA, COLUMN_ICON, m_grid->GetCellRenderer( aRowB, COLUMN_ICON ) );
137  m_grid->SetCellRenderer( aRowB, COLUMN_ICON, cellRenderer );
138 
139  m_grid->Thaw();
140 }

References COLUMN_ICON, and PANEL_PCBNEW_ACTION_PLUGINS_BASE::m_grid.

Referenced by OnMoveDownButtonClick(), and OnMoveUpButtonClick().

◆ TransferDataFromWindow()

bool PANEL_PCBNEW_ACTION_PLUGINS::TransferDataFromWindow ( )
override

Definition at line 150 of file panel_pcbnew_action_plugins.cpp.

151 {
152  PCBNEW_SETTINGS* settings = dynamic_cast<PCBNEW_SETTINGS*>( Kiface().KifaceSettings() );
153  wxASSERT( settings );
154 
155  if( settings )
156  {
157  settings->m_VisibleActionPlugins.clear();
158 
159  for( int ii = 0; ii < m_grid->GetNumberRows(); ii++ )
160  {
161  settings->m_VisibleActionPlugins.emplace_back( std::make_pair(
162  m_grid->GetCellValue( ii, COLUMN_PATH ),
163  m_grid->GetCellValue( ii, COLUMN_VISIBLE ) == wxT( "1" ) ) );
164  }
165  }
166 
167  return true;
168 }
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
ACTION_PLUGIN_SETTINGS_LIST m_VisibleActionPlugins

References COLUMN_PATH, COLUMN_VISIBLE, Kiface(), PANEL_PCBNEW_ACTION_PLUGINS_BASE::m_grid, and PCBNEW_SETTINGS::m_VisibleActionPlugins.

◆ TransferDataToWindow()

bool PANEL_PCBNEW_ACTION_PLUGINS::TransferDataToWindow ( )
override

Definition at line 171 of file panel_pcbnew_action_plugins.cpp.

172 {
173  m_grid->Freeze();
174 
175  m_grid->ClearRows();
176 
177  const auto& orderedPlugins = m_frame->GetOrderedActionPlugins();
178  m_grid->AppendRows( orderedPlugins.size() );
179 
180  for( size_t row = 0; row < orderedPlugins.size(); row++ )
181  {
182  ACTION_PLUGIN* ap = orderedPlugins[row];
183 
184  // Icon
185  m_grid->SetCellRenderer( row, COLUMN_ICON, new GRID_CELL_ICON_RENDERER(
186  ap->iconBitmap.IsOk() ? ap->iconBitmap : m_genericIcon ) );
187 
188  // Toolbar button checkbox
189  m_grid->SetCellRenderer( row, COLUMN_VISIBLE, new wxGridCellBoolRenderer() );
190  m_grid->SetCellAlignment( row, COLUMN_VISIBLE, wxALIGN_CENTER, wxALIGN_CENTER );
191 
192  bool showButton = m_frame->GetActionPluginButtonVisible( ap->GetPluginPath(),
193  ap->GetShowToolbarButton() );
194 
195  m_grid->SetCellValue( row, COLUMN_VISIBLE, showButton ? wxT( "1" ) : wxEmptyString );
196 
197  m_grid->SetCellValue( row, COLUMN_NAME, ap->GetName() );
198  m_grid->SetCellValue( row, COLUMN_CATEGORY, ap->GetCategoryName() );
199  m_grid->SetCellValue( row, COLUMN_DESCRIPTION, ap->GetDescription() );
200  m_grid->SetCellValue( row, COLUMN_PATH, ap->GetPluginPath() );
201  }
202 
203  for( int col = 0; col < m_grid->GetNumberCols(); col++ )
204  {
205  const wxString& heading = m_grid->GetColLabelValue( col );
206  int headingWidth = GetTextExtent( heading ).x + 2 * GRID_CELL_MARGIN;
207 
208  // Set the minimal width to the column label size.
209  m_grid->SetColMinimalWidth( col, headingWidth );
210  // Set the width to see the full contents
211  m_grid->SetColSize( col, m_grid->GetVisibleWidth( col, true, true, false ) );
212  }
213 
214  m_grid->AutoSizeRows();
215 
216  m_grid->Thaw();
217 
218  // Show errors button should be disabled if there are no errors.
219  wxString trace;
220  pcbnewGetWizardsBackTrace( trace );
221  if( trace.empty() )
222  {
223  m_showErrorsButton->Disable();
224  m_showErrorsButton->Hide();
225  }
226  else
227  {
228  m_showErrorsButton->Enable();
229  m_showErrorsButton->Show();
230  }
231 
232  return true;
233 }
virtual wxString GetName()=0
This is the parent class from where any action plugin class must derive.
Definition: action_plugin.h:38
virtual bool GetShowToolbarButton()=0
virtual wxString GetDescription()=0
wxBitmap iconBitmap
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...
int GetVisibleWidth(int aCol, bool aHeader=true, bool aContents=false, bool aKeep=true)
Calculates the specified column based on the actual size of the text on screen.
Definition: wx_grid.cpp:246
#define GRID_CELL_MARGIN
virtual wxString GetPluginPath()=0
void pcbnewGetWizardsBackTrace(wxString &aTrace)
Return the backtrace of errors (if any) when wizard python scripts are loaded.
std::vector< ACTION_PLUGIN * > GetOrderedActionPlugins()
Return ordered list of plugins in sequence in which they should appear on toolbar or in settings.
virtual wxString GetCategoryName()=0
void ClearRows()
wxWidgets recently added an ASSERT which fires if the position is greater than or equal to the number...
Definition: wx_grid.h:106

References WX_GRID::ClearRows(), COLUMN_CATEGORY, COLUMN_DESCRIPTION, COLUMN_ICON, COLUMN_NAME, COLUMN_PATH, COLUMN_VISIBLE, PCB_EDIT_FRAME::GetActionPluginButtonVisible(), ACTION_PLUGIN::GetCategoryName(), ACTION_PLUGIN::GetDescription(), ACTION_PLUGIN::GetName(), PCB_EDIT_FRAME::GetOrderedActionPlugins(), ACTION_PLUGIN::GetPluginPath(), ACTION_PLUGIN::GetShowToolbarButton(), WX_GRID::GetVisibleWidth(), GRID_CELL_MARGIN, ACTION_PLUGIN::iconBitmap, m_frame, m_genericIcon, PANEL_PCBNEW_ACTION_PLUGINS_BASE::m_grid, PANEL_PCBNEW_ACTION_PLUGINS_BASE::m_showErrorsButton, and pcbnewGetWizardsBackTrace().

Referenced by OnReloadButtonClick().

Member Data Documentation

◆ m_frame

PCB_EDIT_FRAME* PANEL_PCBNEW_ACTION_PLUGINS::m_frame
private

◆ m_genericIcon

wxBitmap PANEL_PCBNEW_ACTION_PLUGINS::m_genericIcon
private

◆ m_grid

◆ m_moveDownButton

wxBitmapButton* PANEL_PCBNEW_ACTION_PLUGINS_BASE::m_moveDownButton
protectedinherited

◆ m_moveUpButton

wxBitmapButton* PANEL_PCBNEW_ACTION_PLUGINS_BASE::m_moveUpButton
protectedinherited

◆ m_openDirectoryButton

wxBitmapButton* PANEL_PCBNEW_ACTION_PLUGINS_BASE::m_openDirectoryButton
protectedinherited

◆ m_reloadButton

wxBitmapButton* PANEL_PCBNEW_ACTION_PLUGINS_BASE::m_reloadButton
protectedinherited

◆ m_showErrorsButton


The documentation for this class was generated from the following files: