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 OnReloadButtonClick (wxCommandEvent &event) override
 Reloads plugins and updates grid. More...
 

Protected Attributes

WX_GRIDm_grid
 
wxBitmapButton * m_moveUpButton
 
wxBitmapButton * m_moveDownButton
 
wxBitmapButton * m_reloadButton
 

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

34  :
36  m_frame( aFrame )
37 {
39  m_grid->PushEventHandler( new GRID_TRICKS( m_grid ) );
40 
41  m_moveUpButton->SetBitmap( KiBitmap( small_up_xpm ) );
42  m_moveDownButton->SetBitmap( KiBitmap( small_down_xpm ) );
43  m_reloadButton->SetBitmap( KiBitmap( refresh_xpm ) );
44 }
GRID_TRICKS is used to add mouse and command handling (such as cut, copy, and paste) to a WX_GRID ins...
Definition: grid_tricks.h:51
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:45
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:80
const BITMAP_OPAQUE small_down_xpm[1]
Definition: small_down.cpp:25
const BITMAP_OPAQUE hammer_xpm[1]
Definition: hammer.cpp:74
const BITMAP_OPAQUE small_up_xpm[1]
Definition: small_up.cpp:26
const BITMAP_OPAQUE refresh_xpm[1]
Definition: refresh.cpp:32

References hammer_xpm, 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_reloadButton, refresh_xpm, small_down_xpm, and small_up_xpm.

◆ ~PANEL_PCBNEW_ACTION_PLUGINS()

PANEL_PCBNEW_ACTION_PLUGINS::~PANEL_PCBNEW_ACTION_PLUGINS ( )
override

Definition at line 47 of file panel_pcbnew_action_plugins.cpp.

48 {
49  m_grid->PopEventHandler( true );
50 }

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

54 {
55  SelectRow( event.GetRow() );
56 }

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

89 {
90  auto selectedRows = m_grid->GetSelectedRows();
91 
92  // If nothing is selected or multiple rows are selected don't do anything.
93  if( selectedRows.size() != 1 ) return;
94 
95  int selectedRow = selectedRows[0];
96 
97  // If last row is selected, then it can't go any further down.
98  if( selectedRow + 1 == m_grid->GetNumberRows() )
99  {
100  wxBell();
101  return;
102  }
103 
104  SwapRows( selectedRow, selectedRow + 1 );
105 
106  SelectRow( selectedRow + 1 );
107 }

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

67 {
68  auto selectedRows = m_grid->GetSelectedRows();
69 
70  // If nothing is selected or multiple rows are selected don't do anything.
71  if( selectedRows.size() != 1 ) return;
72 
73  int selectedRow = selectedRows[0];
74 
75  // If first row is selected, then it can't go any further up.
76  if( selectedRow == 0 )
77  {
78  wxBell();
79  return;
80  }
81 
82  SwapRows( selectedRow, selectedRow - 1 );
83 
84  SelectRow( selectedRow - 1 );
85 }

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

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

134 {
137 }
void PythonPluginsReload()
Reload the Python plugins if they are newer than the already loaded, and load new plugins if any Do n...

References m_frame, PCB_EDIT_FRAME::PythonPluginsReload(), and TransferDataToWindow().

◆ SelectRow()

void PANEL_PCBNEW_ACTION_PLUGINS::SelectRow ( int  aRow)
private

Definition at line 59 of file panel_pcbnew_action_plugins.cpp.

60 {
61  m_grid->ClearSelection();
62  m_grid->SelectRow( aRow );
63 }

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

111 {
112  m_grid->Freeze();
113 
114  // Swap all columns except icon
115  wxString tempStr;
116 
117  for( int column = 1; column < m_grid->GetNumberCols(); column++ )
118  {
119  tempStr = m_grid->GetCellValue( aRowA, column );
120  m_grid->SetCellValue( aRowA, column, m_grid->GetCellValue( aRowB, column ) );
121  m_grid->SetCellValue( aRowB, column, tempStr );
122  }
123 
124  // Swap icon column renderers
125  auto cellRenderer = m_grid->GetCellRenderer( aRowA, COLUMN_ICON );
126  m_grid->SetCellRenderer( aRowA, COLUMN_ICON, m_grid->GetCellRenderer( aRowB, COLUMN_ICON ) );
127  m_grid->SetCellRenderer( aRowB, COLUMN_ICON, cellRenderer );
128 
129  m_grid->Thaw();
130 }

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

141 {
142  PCBNEW_SETTINGS* settings = dynamic_cast<PCBNEW_SETTINGS*>( Kiface().KifaceSettings() );
143  wxASSERT( settings );
144 
145  if( settings )
146  {
147  settings->m_VisibleActionPlugins.clear();
148 
149  for( int ii = 0; ii < m_grid->GetNumberRows(); ii++ )
150  {
151  settings->m_VisibleActionPlugins.emplace_back( std::make_pair(
152  m_grid->GetCellValue( ii, COLUMN_PATH ),
153  m_grid->GetCellValue( ii, COLUMN_VISIBLE ) == wxT( "1" ) ) );
154  }
155  }
156 
157  return true;
158 }
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 161 of file panel_pcbnew_action_plugins.cpp.

162 {
163  m_grid->Freeze();
164 
165  if( m_grid->GetNumberRows() != 0 )
166  m_grid->DeleteRows( 0, m_grid->GetNumberRows() );
167 
168  const auto& orderedPlugins = m_frame->GetOrderedActionPlugins();
169  m_grid->AppendRows( orderedPlugins.size() );
170 
171  for( size_t row = 0; row < orderedPlugins.size(); row++ )
172  {
173  ACTION_PLUGIN* ap = orderedPlugins[row];
174 
175  // Icon
176  m_grid->SetCellRenderer( row, COLUMN_ICON, new GRID_CELL_ICON_RENDERER(
177  ap->iconBitmap.IsOk() ? ap->iconBitmap : m_genericIcon ) );
178 
179  // Toolbar button checkbox
180  m_grid->SetCellRenderer( row, COLUMN_VISIBLE, new wxGridCellBoolRenderer() );
181  m_grid->SetCellAlignment( row, COLUMN_VISIBLE, wxALIGN_CENTER, wxALIGN_CENTER );
182 
183  bool showButton = m_frame->GetActionPluginButtonVisible( ap->GetPluginPath(),
184  ap->GetShowToolbarButton() );
185 
186  m_grid->SetCellValue( row, COLUMN_VISIBLE, showButton ? wxT( "1" ) : wxEmptyString );
187 
188  m_grid->SetCellValue( row, COLUMN_NAME, ap->GetName() );
189  m_grid->SetCellValue( row, COLUMN_CATEGORY, ap->GetCategoryName() );
190  m_grid->SetCellValue( row, COLUMN_DESCRIPTION, ap->GetDescription() );
191  m_grid->SetCellValue( row, COLUMN_PATH, ap->GetPluginPath() );
192  }
193 
194  for( int col = 0; col < m_grid->GetNumberCols(); col++ )
195  {
196  // Set the minimal width to the column label size.
197  m_grid->SetColMinimalWidth( col, m_grid->GetVisibleWidth( col, true, false, false ) );
198  // Set the width to see the full contents
199  m_grid->SetColSize( col, m_grid->GetVisibleWidth( col, true, true, false ) );
200  }
201 
202  m_grid->AutoSizeRows();
203 
204  m_grid->Thaw();
205 
206  return true;
207 }
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
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:230
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(), ACTION_PLUGIN::iconBitmap, m_frame, m_genericIcon, and PANEL_PCBNEW_ACTION_PLUGINS_BASE::m_grid.

Referenced by OnReloadButtonClick().

Member Data Documentation

◆ m_frame

PCB_EDIT_FRAME* PANEL_PCBNEW_ACTION_PLUGINS::m_frame
private

Definition at line 64 of file panel_pcbnew_action_plugins.h.

Referenced by OnReloadButtonClick(), and TransferDataToWindow().

◆ 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_reloadButton

wxBitmapButton* PANEL_PCBNEW_ACTION_PLUGINS_BASE::m_reloadButton
protectedinherited

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