KiCad PCB EDA Suite
Loading...
Searching...
No Matches
panel_pcbnew_action_plugins.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2018 Andrew Lutsenko, anlutsenko at gmail dot com
5 * Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#include <action_plugin.h>
22#include <bitmaps.h>
24#include <grid_tricks.h>
25#include <kiface_base.h>
27#include <pcb_edit_frame.h>
29#include <pcb_scripting_tool.h>
30#include <pcbnew_settings.h>
33#include <widgets/wx_grid.h>
35
36
37#define GRID_CELL_MARGIN 4
38
41{
42 m_genericIcon = KiBitmap( BITMAPS::puzzle_piece );
43 m_grid->PushEventHandler( new GRID_TRICKS( m_grid ) );
44 m_grid->SetUseNativeColLabels();
45
46 m_moveUpButton->SetBitmap( KiBitmapBundle( BITMAPS::small_up ) );
47 m_moveDownButton->SetBitmap( KiBitmapBundle( BITMAPS::small_down ) );
48 m_openDirectoryButton->SetBitmap( KiBitmapBundle( BITMAPS::small_folder ) );
49 m_reloadButton->SetBitmap( KiBitmapBundle( BITMAPS::small_refresh ) );
50 m_showErrorsButton->SetBitmap( KiBitmapBundle( BITMAPS::small_warning ) );
51}
52
53
55{
56 m_grid->PopEventHandler( true );
57}
58
59
61{
62 SelectRow( event.GetRow() );
63}
64
65
67{
68 m_grid->ClearSelection();
69 m_grid->SelectRow( aRow );
70}
71
72
74{
75 auto selectedRows = m_grid->GetSelectedRows();
76
77 // If nothing is selected or multiple rows are selected don't do anything.
78 if( selectedRows.size() != 1 ) return;
79
80 int selectedRow = selectedRows[0];
81
82 // If first row is selected, then it can't go any further up.
83 if( selectedRow == 0 )
84 {
85 wxBell();
86 return;
87 }
88
89 SwapRows( selectedRow, selectedRow - 1 );
90
91 SelectRow( selectedRow - 1 );
92}
93
94
96{
97 auto selectedRows = m_grid->GetSelectedRows();
98
99 // If nothing is selected or multiple rows are selected don't do anything.
100 if( selectedRows.size() != 1 ) return;
101
102 int selectedRow = selectedRows[0];
103
104 // If last row is selected, then it can't go any further down.
105 if( selectedRow + 1 == m_grid->GetNumberRows() )
106 {
107 wxBell();
108 return;
109 }
110
111 SwapRows( selectedRow, selectedRow + 1 );
112
113 SelectRow( selectedRow + 1 );
114}
115
116
117void PANEL_PCBNEW_ACTION_PLUGINS::SwapRows( int aRowA, int aRowB )
118{
119 m_grid->Freeze();
120
121 // Swap all columns except icon
122 wxString tempStr;
123
124 for( int column = 1; column < m_grid->GetNumberCols(); column++ )
125 {
126 tempStr = m_grid->GetCellValue( aRowA, column );
127 m_grid->SetCellValue( aRowA, column, m_grid->GetCellValue( aRowB, column ) );
128 m_grid->SetCellValue( aRowB, column, tempStr );
129 }
130
131 // Swap icon column renderers
132 auto cellRenderer = m_grid->GetCellRenderer( aRowA, COLUMN_ICON );
133 m_grid->SetCellRenderer( aRowA, COLUMN_ICON, m_grid->GetCellRenderer( aRowB, COLUMN_ICON ) );
134 m_grid->SetCellRenderer( aRowB, COLUMN_ICON, cellRenderer );
135
136 m_grid->Thaw();
137}
138
139
141{
144}
145
146
148{
149 PCBNEW_SETTINGS* settings = dynamic_cast<PCBNEW_SETTINGS*>( Kiface().KifaceSettings() );
150 wxASSERT( settings );
151
152 if( settings )
153 {
154 settings->m_VisibleActionPlugins.clear();
155
156 for( int ii = 0; ii < m_grid->GetNumberRows(); ii++ )
157 {
158 settings->m_VisibleActionPlugins.emplace_back( std::make_pair(
159 m_grid->GetCellValue( ii, COLUMN_PATH ),
160 m_grid->GetCellValue( ii, COLUMN_VISIBLE ) == wxT( "1" ) ) );
161 }
162 }
163
164 return true;
165}
166
167
169{
170 m_grid->Freeze();
171
172 m_grid->ClearRows();
173
174 const auto& orderedPlugins = PCB_EDIT_FRAME::GetOrderedActionPlugins();
175 m_grid->AppendRows( orderedPlugins.size() );
176
177 for( size_t row = 0; row < orderedPlugins.size(); row++ )
178 {
179 ACTION_PLUGIN* ap = orderedPlugins[row];
180
181 // Icon
182 m_grid->SetCellRenderer( row, COLUMN_ICON, new GRID_CELL_ICON_RENDERER(
183 ap->iconBitmap.IsOk() ? ap->iconBitmap : m_genericIcon ) );
184
185 // Toolbar button checkbox
186 m_grid->SetCellRenderer( row, COLUMN_VISIBLE, new wxGridCellBoolRenderer() );
187 m_grid->SetCellAlignment( row, COLUMN_VISIBLE, wxALIGN_CENTER, wxALIGN_CENTER );
188
190 ap->GetShowToolbarButton() );
191
192 m_grid->SetCellValue( row, COLUMN_VISIBLE, show ? wxT( "1" ) : wxEmptyString );
193
194 m_grid->SetCellValue( row, COLUMN_NAME, ap->GetName() );
195 m_grid->SetCellValue( row, COLUMN_CATEGORY, ap->GetCategoryName() );
196 m_grid->SetCellValue( row, COLUMN_DESCRIPTION, ap->GetDescription() );
197 m_grid->SetCellValue( row, COLUMN_PATH, ap->GetPluginPath() );
198 }
199
200 for( int col = 0; col < m_grid->GetNumberCols(); col++ )
201 {
202 const wxString& heading = m_grid->GetColLabelValue( col );
203 int headingWidth = GetTextExtent( heading ).x + 2 * GRID_CELL_MARGIN;
204
205 // Set the minimal width to the column label size.
206 m_grid->SetColMinimalWidth( col, headingWidth );
207 // Set the width to see the full contents
208 m_grid->SetColSize( col, m_grid->GetVisibleWidth( col ) );
209 }
210
211 m_grid->AutoSizeRows();
212
213 m_grid->Thaw();
214
215 // Show errors button should be disabled if there are no errors.
216 wxString trace;
217
220
221 if( trace.empty() )
222 {
223 m_showErrorsButton->Disable();
224 m_showErrorsButton->Hide();
225 }
226 else
227 {
229 m_showErrorsButton->Show();
230 }
231
232 return true;
233}
234
235
237{
239}
240
241
243{
244 wxString 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( wxGetTopLevelParent( this ) );
250 logWindow.m_Message->SetValue( trace );
251 logWindow.ShowModal();
252}
Class PCBNEW_ACTION_PLUGINS.
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap)
Definition: bitmap.cpp:110
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:104
static int GetActionsCount()
This is the parent class from where any action plugin class must derive.
Definition: action_plugin.h:39
wxBitmap iconBitmap
virtual wxString GetDescription()=0
virtual wxString GetPluginPath()=0
virtual wxString GetCategoryName()=0
virtual wxString GetName()=0
virtual bool GetShowToolbarButton()=0
Class DIALOG_FOOTPRINT_WIZARD_LOG.
int ShowModal() override
Add mouse and command handling (such as cut, copy, and paste) to a WX_GRID instance.
Definition: grid_tricks.h:61
APP_SETTINGS_BASE * KifaceSettings() const
Definition: kiface_base.h:95
Class PANEL_PCBNEW_ACTION_PLUGINS_BASE.
void OnShowErrorsButtonClick(wxCommandEvent &event) override
Shows plugin import errors.
void OnMoveUpButtonClick(wxCommandEvent &event) override
Moves plugin up in the grid.
void OnGridCellClick(wxGridEvent &event) override
Selects a whole row.
void OnMoveDownButtonClick(wxCommandEvent &event) override
Moves plugin down in the grid.
void OnOpenDirectoryButtonClick(wxCommandEvent &event) override
Opens user's action plugin directory.
void OnReloadButtonClick(wxCommandEvent &event) override
Reloads plugins and updates grid.
ACTION_PLUGIN_SETTINGS_LIST m_VisibleActionPlugins
static std::vector< ACTION_PLUGIN * > GetOrderedActionPlugins()
Return ordered list of plugins in sequence in which they should appear on toolbar or in settings.
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...
static void ShowPluginFolder()
static void ReloadPlugins()
bool Enable(bool aEnable=true) override
void SetBitmap(const wxBitmapBundle &aBmp)
int GetVisibleWidth(int aCol, bool aHeader=true, bool aContents=true, bool aKeep=false)
Calculates the specified column based on the actual size of the text on screen.
Definition: wx_grid.cpp:769
void ClearRows()
wxWidgets recently added an ASSERT which fires if the position is greater than or equal to the number...
Definition: wx_grid.h:184
#define GRID_CELL_MARGIN
void pcbnewGetWizardsBackTrace(wxString &aTrace)
Return the backtrace of errors (if any) when wizard python scripts are loaded.