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

Constructor & Destructor Documentation

PANEL_PCBNEW_ACTION_PLUGINS::PANEL_PCBNEW_ACTION_PLUGINS ( PCB_EDIT_FRAME aFrame,
PAGED_DIALOG aWindow 
)

Definition at line 31 of file panel_pcbnew_action_plugins.cpp.

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, and PANEL_PCBNEW_ACTION_PLUGINS_BASE::m_reloadButton.

31  :
33  m_frame( aFrame )
34 {
35  m_genericIcon = KiBitmap( hammer_xpm );
36  m_grid->PushEventHandler( new GRID_TRICKS( m_grid ) );
37 
38  m_moveUpButton->SetBitmap( KiBitmap( small_up_xpm ) );
39  m_moveDownButton->SetBitmap( KiBitmap( small_down_xpm ) );
40  m_reloadButton->SetBitmap( KiBitmap( refresh_xpm ) );
41 }
Class GRID_TRICKS is used to add cut, copy, and paste to an otherwise unmodied wxGrid instance...
Definition: grid_tricks.h:51
PANEL_PCBNEW_ACTION_PLUGINS_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(485, 200), long style=wxTAB_TRAVERSAL, const wxString &name=wxEmptyString)
wxTreebook * GetTreebook()
Definition: paged_dialog.h:43
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:79
PANEL_PCBNEW_ACTION_PLUGINS::~PANEL_PCBNEW_ACTION_PLUGINS ( )
override

Definition at line 44 of file panel_pcbnew_action_plugins.cpp.

References PANEL_PCBNEW_ACTION_PLUGINS_BASE::m_grid.

45 {
46  m_grid->PopEventHandler( true );
47 }

Member Function Documentation

void PANEL_PCBNEW_ACTION_PLUGINS::OnGridCellClick ( wxGridEvent &  event)
overridevirtual

Selects a whole row.

Reimplemented from PANEL_PCBNEW_ACTION_PLUGINS_BASE.

Definition at line 50 of file panel_pcbnew_action_plugins.cpp.

References SelectRow().

51 {
52  SelectRow( event.GetRow() );
53 }
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 85 of file panel_pcbnew_action_plugins.cpp.

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

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

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

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

Reloads plugins and updates grid.

Reimplemented from PANEL_PCBNEW_ACTION_PLUGINS_BASE.

Definition at line 130 of file panel_pcbnew_action_plugins.cpp.

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

131 {
134 }
void PythonPluginsReload()
Reload the Python plugins if they are newer than the already loaded, and load new plugins if any Do n...
void PANEL_PCBNEW_ACTION_PLUGINS::SelectRow ( int  aRow)
private

Definition at line 56 of file panel_pcbnew_action_plugins.cpp.

References PANEL_PCBNEW_ACTION_PLUGINS_BASE::m_grid.

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

57 {
58  m_grid->ClearSelection();
59  m_grid->SelectRow( aRow );
60 }
void PANEL_PCBNEW_ACTION_PLUGINS::SwapRows ( int  aRowA,
int  aRowB 
)
private

Definition at line 107 of file panel_pcbnew_action_plugins.cpp.

References COLUMN_ICON, and PANEL_PCBNEW_ACTION_PLUGINS_BASE::m_grid.

Referenced by OnMoveDownButtonClick(), and OnMoveUpButtonClick().

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

Definition at line 137 of file panel_pcbnew_action_plugins.cpp.

References COLUMN_PATH, COLUMN_VISIBLE, m_frame, and PANEL_PCBNEW_ACTION_PLUGINS_BASE::m_grid.

138 {
139  std::vector< std::pair<wxString, wxString> > pluginSettings;
140 
141  for( int ii = 0; ii < m_grid->GetNumberRows(); ii++ )
142  {
143  pluginSettings.push_back( std::make_pair(
144  m_grid->GetCellValue( ii, COLUMN_PATH ),
145  m_grid->GetCellValue( ii, COLUMN_VISIBLE ) == wxT("1") ? wxT( "Visible" ) : wxT( "Hidden" )
146  ) );
147  }
148 
149  m_frame->SetActionPluginSettings( pluginSettings );
150 
151  return true;
152 }
bool PANEL_PCBNEW_ACTION_PLUGINS::TransferDataToWindow ( )
override

Definition at line 155 of file panel_pcbnew_action_plugins.cpp.

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(), ACTION_PLUGIN::iconBitmap, m_frame, m_genericIcon, and PANEL_PCBNEW_ACTION_PLUGINS_BASE::m_grid.

Referenced by OnReloadButtonClick().

156 {
157  m_grid->Freeze();
158  if( m_grid->GetNumberRows() != 0 )
159  m_grid->DeleteRows( 0, m_grid->GetNumberRows() );
160 
161  const auto& orderedPlugins = m_frame->GetOrderedActionPlugins();
162  m_grid->AppendRows( orderedPlugins.size() );
163 
164  for( size_t row = 0; row < orderedPlugins.size(); row++ )
165  {
166  ACTION_PLUGIN* ap = orderedPlugins[row];
167 
168  // Icon
169  m_grid->SetCellRenderer( row, COLUMN_ICON, new GRID_CELL_ICON_RENDERER(
170  ap->iconBitmap.IsOk() ? ap->iconBitmap : m_genericIcon ) );
171 
172  // Toolbar button checkbox
173  m_grid->SetCellRenderer( row, COLUMN_VISIBLE, new wxGridCellBoolRenderer() );
174  m_grid->SetCellAlignment( row, COLUMN_VISIBLE, wxALIGN_CENTER, wxALIGN_CENTER );
175 
176  bool showButton = m_frame->GetActionPluginButtonVisible(
177  ap->GetPluginPath(), ap->GetShowToolbarButton() );
178 
179  m_grid->SetCellValue( row, COLUMN_VISIBLE, showButton ? wxT( "1" ) : wxEmptyString );
180 
181  // Name
182  m_grid->SetCellValue( row, COLUMN_NAME, ap->GetName() );
183 
184  // Category
185  m_grid->SetCellValue( row, COLUMN_CATEGORY, ap->GetCategoryName() );
186 
187  // Description
188  m_grid->SetCellValue( row, COLUMN_DESCRIPTION, ap->GetDescription() );
189 
190  // Path
191  m_grid->SetCellValue( row, COLUMN_PATH, ap->GetPluginPath() );
192  }
193 
194  m_grid->AutoSizeColumns();
195  m_grid->AutoSizeRows();
196 
197  m_grid->Thaw();
198 
199  return true;
200 }
virtual wxString GetName()=0
Function GetName.
Class 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
virtual wxString GetPluginPath()=0
Function GetPluginPath.
virtual wxString GetCategoryName()=0
Function GetCategoryName.

Member Data Documentation

PCB_EDIT_FRAME* PANEL_PCBNEW_ACTION_PLUGINS::m_frame
private
wxBitmap PANEL_PCBNEW_ACTION_PLUGINS::m_genericIcon
private
wxBitmapButton* PANEL_PCBNEW_ACTION_PLUGINS_BASE::m_moveDownButton
protectedinherited
wxBitmapButton* PANEL_PCBNEW_ACTION_PLUGINS_BASE::m_moveUpButton
protectedinherited
wxBitmapButton* PANEL_PCBNEW_ACTION_PLUGINS_BASE::m_reloadButton
protectedinherited

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