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 42 of file panel_pcbnew_action_plugins.cpp.

43  :
45  m_frame( aFrame )
46 {
48  m_grid->PushEventHandler( new GRID_TRICKS( m_grid ) );
49 
50  m_moveUpButton->SetBitmap( KiBitmap( BITMAPS::small_up ) );
55 }
Add mouse and command handling (such as cut, copy, and paste) to a WX_GRID instance.
Definition: grid_tricks.h:52
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:52
wxBitmap KiBitmap(BITMAPS aBitmap)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
Definition: bitmap.cpp:104

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 58 of file panel_pcbnew_action_plugins.cpp.

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

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 64 of file panel_pcbnew_action_plugins.cpp.

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

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 99 of file panel_pcbnew_action_plugins.cpp.

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

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 77 of file panel_pcbnew_action_plugins.cpp.

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

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 237 of file panel_pcbnew_action_plugins.cpp.

238 {
240 }
void PythonPluginsShowFolder()
Open the plugins folder in the default system file browser.

References m_frame, and PCB_EDIT_FRAME::PythonPluginsShowFolder().

◆ 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 144 of file panel_pcbnew_action_plugins.cpp.

145 {
148 }
void PythonPluginsReload()
Reload the Python plugins if they are newer than the already loaded, and load new plugins if any.

References m_frame, PCB_EDIT_FRAME::PythonPluginsReload(), 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 242 of file panel_pcbnew_action_plugins.cpp.

243 {
244  wxString trace;
245  pcbnewGetWizardsBackTrace( trace );
246 
247  // Now display the filtered trace in our dialog
248  // (a simple wxMessageBox is really not suitable for long messages)
249  DIALOG_FOOTPRINT_WIZARD_LOG logWindow( this );
250  logWindow.m_Message->SetValue( trace );
251  logWindow.ShowModal();
252 }
static void pcbnewGetWizardsBackTrace(wxString &aText)
Class DIALOG_FOOTPRINT_WIZARD_LOG.

References DIALOG_FOOTPRINT_WIZARD_LOG::m_Message, and pcbnewGetWizardsBackTrace().

◆ SelectRow()

void PANEL_PCBNEW_ACTION_PLUGINS::SelectRow ( int  aRow)
private

Definition at line 70 of file panel_pcbnew_action_plugins.cpp.

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

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 121 of file panel_pcbnew_action_plugins.cpp.

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

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 151 of file panel_pcbnew_action_plugins.cpp.

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

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

◆ TransferDataToWindow()

bool PANEL_PCBNEW_ACTION_PLUGINS::TransferDataToWindow ( )
override

Definition at line 172 of file panel_pcbnew_action_plugins.cpp.

173 {
174  m_grid->Freeze();
175 
176  if( m_grid->GetNumberRows() != 0 )
177  m_grid->DeleteRows( 0, m_grid->GetNumberRows() );
178 
179  const auto& orderedPlugins = m_frame->GetOrderedActionPlugins();
180  m_grid->AppendRows( orderedPlugins.size() );
181 
182  for( size_t row = 0; row < orderedPlugins.size(); row++ )
183  {
184  ACTION_PLUGIN* ap = orderedPlugins[row];
185 
186  // Icon
187  m_grid->SetCellRenderer( row, COLUMN_ICON, new GRID_CELL_ICON_RENDERER(
188  ap->iconBitmap.IsOk() ? ap->iconBitmap : m_genericIcon ) );
189 
190  // Toolbar button checkbox
191  m_grid->SetCellRenderer( row, COLUMN_VISIBLE, new wxGridCellBoolRenderer() );
192  m_grid->SetCellAlignment( row, COLUMN_VISIBLE, wxALIGN_CENTER, wxALIGN_CENTER );
193 
194  bool showButton = m_frame->GetActionPluginButtonVisible( ap->GetPluginPath(),
195  ap->GetShowToolbarButton() );
196 
197  m_grid->SetCellValue( row, COLUMN_VISIBLE, showButton ? wxT( "1" ) : wxEmptyString );
198 
199  m_grid->SetCellValue( row, COLUMN_NAME, ap->GetName() );
200  m_grid->SetCellValue( row, COLUMN_CATEGORY, ap->GetCategoryName() );
201  m_grid->SetCellValue( row, COLUMN_DESCRIPTION, ap->GetDescription() );
202  m_grid->SetCellValue( row, COLUMN_PATH, ap->GetPluginPath() );
203  }
204 
205  for( int col = 0; col < m_grid->GetNumberCols(); col++ )
206  {
207  const wxString& heading = m_grid->GetColLabelValue( col );
208  int headingWidth = GetTextExtent( heading ).x + 2 * GRID_CELL_MARGIN;
209 
210  // Set the minimal width to the column label size.
211  m_grid->SetColMinimalWidth( col, headingWidth );
212  // Set the width to see the full contents
213  m_grid->SetColSize( col, m_grid->GetVisibleWidth( col, true, true, false ) );
214  }
215 
216  m_grid->AutoSizeRows();
217 
218  m_grid->Thaw();
219 
220  // Show errors button should be disabled if there are no errors.
221  wxString trace;
222  pcbnewGetWizardsBackTrace( trace );
223  if( trace.empty() )
224  {
225  m_showErrorsButton->Disable();
226  m_showErrorsButton->Hide();
227  }
228  else
229  {
230  m_showErrorsButton->Enable();
231  m_showErrorsButton->Show();
232  }
233 
234  return true;
235 }
virtual wxString GetName()=0
Function GetName.
ACTION_PLUGIN This is the parent class from where any action plugin class must derive.
Definition: action_plugin.h:40
static void pcbnewGetWizardsBackTrace(wxString &aText)
virtual bool GetShowToolbarButton()=0
Function GetShowToolbarButton.
virtual wxString GetDescription()=0
Function GetDescription.
wxBitmap iconBitmap
Definition: action_plugin.h:50
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:238
#define GRID_CELL_MARGIN
virtual wxString GetPluginPath()=0
Function GetPluginPath.
virtual wxString GetCategoryName()=0
Function GetCategoryName.

References COLUMN_CATEGORY, COLUMN_DESCRIPTION, COLUMN_ICON, COLUMN_NAME, COLUMN_PATH, COLUMN_VISIBLE, ACTION_PLUGIN::GetCategoryName(), ACTION_PLUGIN::GetDescription(), ACTION_PLUGIN::GetName(), 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: