KiCad PCB EDA Suite
PANEL_FP_EDITOR_DEFAULTS Class Reference

#include <panel_fp_editor_defaults.h>

Inheritance diagram for PANEL_FP_EDITOR_DEFAULTS:
PANEL_FP_EDITOR_DEFAULTS_BASE RESETTABLE_PANEL

Public Member Functions

 PANEL_FP_EDITOR_DEFAULTS (wxWindow *aParent, EDA_BASE_FRAME *aUnitsProvider)
 
 ~PANEL_FP_EDITOR_DEFAULTS () override
 
bool TransferDataToWindow () override
 
bool TransferDataFromWindow () override
 
void ResetPanel () override
 Reset the contents of this panel. More...
 
virtual wxString GetResetTooltip () const
 Get the tooltip the reset button should display when showing this panel. More...
 
wxString GetHelpTextAtPoint (const wxPoint &aPt, wxHelpEvent::Origin aOrigin) const override
 Overridden to supply the reset button tooltip when queried with { -INT_MAX, INT_MAX }. More...
 

Protected Member Functions

virtual void OnGridSize (wxSizeEvent &event)
 

Protected Attributes

wxStaticText * defaultTextItemsLabel
 
WX_GRIDm_textItemsGrid
 
wxBitmapButton * m_bpAdd
 
wxBitmapButton * m_bpDelete
 
wxStaticText * m_staticTextInfo
 
WX_GRIDm_graphicsGrid
 

Private Member Functions

virtual void OnAddTextItem (wxCommandEvent &event) override
 
virtual void OnDeleteTextItem (wxCommandEvent &event) override
 
bool Show (bool aShow) override
 
int getGridValue (int aRow, int aCol)
 
bool validateData ()
 
void loadFPSettings (FOOTPRINT_EDITOR_SETTINGS *aCfg)
 

Private Attributes

EDA_UNITS m_units = EDA_UNITS::MILLIMETRES
 
PAGED_DIALOGm_parent
 
bool m_firstShow = true
 

Detailed Description

Definition at line 29 of file panel_fp_editor_defaults.h.

Constructor & Destructor Documentation

◆ PANEL_FP_EDITOR_DEFAULTS()

PANEL_FP_EDITOR_DEFAULTS::PANEL_FP_EDITOR_DEFAULTS ( wxWindow *  aParent,
EDA_BASE_FRAME aUnitsProvider 
)

Definition at line 172 of file panel_fp_editor_defaults.cpp.

173 :
175{
176 if( aUnitsProvider )
177 m_units = aUnitsProvider->GetUserUnits();
178
179 m_parent = static_cast<PAGED_DIALOG*>( aParent->GetParent() );
180
181 m_textItemsGrid->SetDefaultRowSize( m_textItemsGrid->GetDefaultRowSize() + 4 );
182 m_graphicsGrid->SetDefaultRowSize( m_graphicsGrid->GetDefaultRowSize() + 4 );
183
185 m_textItemsGrid->PushEventHandler( new GRID_TRICKS( m_textItemsGrid ) );
186 m_textItemsGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
187
188 wxGridCellAttr* attr = new wxGridCellAttr;
189 attr->SetRenderer( new wxGridCellBoolRenderer() );
190 attr->SetReadOnly(); // not really; we delegate interactivity to GRID_TRICKS
191 attr->SetAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
192 m_textItemsGrid->SetColAttr( 1, attr );
193
194 attr = new wxGridCellAttr;
195 attr->SetRenderer( new GRID_CELL_LAYER_RENDERER( nullptr ) );
196 attr->SetEditor( new GRID_CELL_LAYER_SELECTOR( nullptr, {} ) );
197 m_textItemsGrid->SetColAttr( 2, attr );
198
199 // Work around a bug in wxWidgets where it fails to recalculate the grid height
200 // after changing the default row size
201 m_graphicsGrid->AppendRows( 1 );
202 m_graphicsGrid->DeleteRows( m_graphicsGrid->GetNumberRows() - 1, 1 );
203
204 m_graphicsGrid->PushEventHandler( new GRID_TRICKS( m_graphicsGrid ) );
205
206 m_staticTextInfo->SetFont( KIUI::GetInfoFont( this ).Italic() );
207}
Add mouse and command handling (such as cut, copy, and paste) to a WX_GRID instance.
Definition: grid_tricks.h:61
PANEL_FP_EDITOR_DEFAULTS_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)
EDA_UNITS GetUserUnits() const
void SetTable(wxGridTableBase *table, bool aTakeOwnership=false)
Hide wxGrid's SetTable() method with one which doesn't mess up the grid column widths when setting th...
Definition: wx_grid.cpp:93
wxFont GetInfoFont(wxWindow *aWindow)
Definition: ui_common.cpp:144

References KIUI::GetInfoFont(), UNITS_PROVIDER::GetUserUnits(), PANEL_FP_EDITOR_DEFAULTS_BASE::m_graphicsGrid, m_parent, PANEL_FP_EDITOR_DEFAULTS_BASE::m_staticTextInfo, PANEL_FP_EDITOR_DEFAULTS_BASE::m_textItemsGrid, m_units, and WX_GRID::SetTable().

◆ ~PANEL_FP_EDITOR_DEFAULTS()

PANEL_FP_EDITOR_DEFAULTS::~PANEL_FP_EDITOR_DEFAULTS ( )
override

Definition at line 210 of file panel_fp_editor_defaults.cpp.

211{
212 // destroy GRID_TRICKS before grids.
213 m_textItemsGrid->PopEventHandler( true );
214 m_graphicsGrid->PopEventHandler( true );
215}

References PANEL_FP_EDITOR_DEFAULTS_BASE::m_graphicsGrid, and PANEL_FP_EDITOR_DEFAULTS_BASE::m_textItemsGrid.

Member Function Documentation

◆ getGridValue()

int PANEL_FP_EDITOR_DEFAULTS::getGridValue ( int  aRow,
int  aCol 
)
private

Definition at line 318 of file panel_fp_editor_defaults.cpp.

319{
320 return EDA_UNIT_UTILS::UI::ValueFromString( pcbIUScale, m_units, m_graphicsGrid->GetCellValue( aRow, aCol ) );
321}
constexpr EDA_IU_SCALE pcbIUScale
Definition: base_units.h:109
long long int ValueFromString(const EDA_IU_SCALE &aIuScale, EDA_UNITS aUnits, const wxString &aTextValue, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
Function ValueFromString converts aTextValue in aUnits to internal units used by the application.
Definition: eda_units.cpp:530

References PANEL_FP_EDITOR_DEFAULTS_BASE::m_graphicsGrid, m_units, pcbIUScale, and EDA_UNIT_UTILS::UI::ValueFromString().

Referenced by TransferDataFromWindow(), and validateData().

◆ GetHelpTextAtPoint()

wxString RESETTABLE_PANEL::GetHelpTextAtPoint ( const wxPoint &  aPt,
wxHelpEvent::Origin  aOrigin 
) const
inlineoverrideinherited

Overridden to supply the reset button tooltip when queried with { -INT_MAX, INT_MAX }.

Definition at line 72 of file resettable_panel.h.

73 {
74 if( aPt == wxPoint( -INT_MAX, INT_MAX ) )
75 return GetResetTooltip();
76 else
77 return wxPanel::GetHelpTextAtPoint( aPt, aOrigin );
78 }
virtual wxString GetResetTooltip() const
Get the tooltip the reset button should display when showing this panel.

References RESETTABLE_PANEL::GetResetTooltip().

◆ GetResetTooltip()

virtual wxString RESETTABLE_PANEL::GetResetTooltip ( ) const
inlinevirtualinherited

Get the tooltip the reset button should display when showing this panel.

Returns
the tooltip

Reimplemented in PANEL_COLOR_SETTINGS, and PANEL_HOTKEYS_EDITOR.

Definition at line 64 of file resettable_panel.h.

65 {
66 return _( "Reset all settings on this page to their default" );
67 }
#define _(s)

References _.

Referenced by RESETTABLE_PANEL::GetHelpTextAtPoint().

◆ loadFPSettings()

void PANEL_FP_EDITOR_DEFAULTS::loadFPSettings ( FOOTPRINT_EDITOR_SETTINGS aCfg)
private

Definition at line 218 of file panel_fp_editor_defaults.cpp.

219{
220 wxColour disabledColour = wxSystemSettings::GetColour( wxSYS_COLOUR_BACKGROUND );
221
222#define SET_MILS_CELL( row, col, val ) \
223 m_graphicsGrid->SetCellValue( row, col, EDA_UNIT_UTILS::UI::StringFromValue( pcbIUScale, m_units, val, true ) )
224
225#define DISABLE_CELL( row, col ) \
226 m_graphicsGrid->SetReadOnly( row, col ); \
227 m_graphicsGrid->SetCellBackgroundColour( row, col, disabledColour );
228
229 for( int i = 0; i < ROW_COUNT; ++i )
230 {
232
233 if( i == ROW_EDGES || i == ROW_COURTYARD )
234 {
239 }
240 else
241 {
245 m_graphicsGrid->SetCellValue( i, COL_TEXT_ITALIC, aCfg->m_DesignSettings.m_TextItalic[ i ] ? wxT( "1" ) : wxT( "" ) );
246
247 auto attr = new wxGridCellAttr;
248 attr->SetRenderer( new wxGridCellBoolRenderer() );
249 attr->SetReadOnly(); // not really; we delegate interactivity to GRID_TRICKS
250 attr->SetAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
251 m_graphicsGrid->SetAttr( i, COL_TEXT_ITALIC, attr );
252 }
253 }
254
255 // Footprint defaults
256 m_textItemsGrid->GetTable()->DeleteRows( 0, m_textItemsGrid->GetNumberRows() );
257 m_textItemsGrid->GetTable()->AppendRows( aCfg->m_DesignSettings.m_DefaultFPTextItems.size() );
258
259 for( size_t i = 0; i < aCfg->m_DesignSettings.m_DefaultFPTextItems.size(); ++i )
260 {
262
263 m_textItemsGrid->GetTable()->SetValue( i, 0, item.m_Text );
264 m_textItemsGrid->GetTable()->SetValueAsBool( i, 1, item.m_Visible );
265 m_textItemsGrid->GetTable()->SetValueAsLong( i, 2, item.m_Layer );
266 }
267
268 for( int col = 0; col < m_graphicsGrid->GetNumberCols(); col++ )
269 {
270 // Set the minimal width to the column label size.
271 m_graphicsGrid->SetColMinimalWidth( col, m_graphicsGrid->GetVisibleWidth( col, true, false ) );
272
273 // Set the width to see the full contents
274 if( m_graphicsGrid->IsColShown( col ) )
275 m_graphicsGrid->SetColSize( col, m_graphicsGrid->GetVisibleWidth( col, true, true, true ) );
276 }
277
278 m_graphicsGrid->SetRowLabelSize( m_graphicsGrid->GetVisibleWidth( -1, true, true, true ) );
279
280 Layout();
281}
std::vector< TEXT_ITEM_INFO > m_DefaultFPTextItems
int m_TextThickness[LAYER_CLASS_COUNT]
int m_LineThickness[LAYER_CLASS_COUNT]
wxSize m_TextSize[LAYER_CLASS_COUNT]
bool m_TextItalic[LAYER_CLASS_COUNT]
BOARD_DESIGN_SETTINGS m_DesignSettings
Only some of these settings are actually used for footprint editing.
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:282
#define SET_MILS_CELL(row, col, val)
#define DISABLE_CELL(row, col)

References COL_LINE_THICKNESS, COL_TEXT_HEIGHT, COL_TEXT_ITALIC, COL_TEXT_THICKNESS, COL_TEXT_WIDTH, DISABLE_CELL, WX_GRID::GetVisibleWidth(), BOARD_DESIGN_SETTINGS::m_DefaultFPTextItems, FOOTPRINT_EDITOR_SETTINGS::m_DesignSettings, PANEL_FP_EDITOR_DEFAULTS_BASE::m_graphicsGrid, TEXT_ITEM_INFO::m_Layer, BOARD_DESIGN_SETTINGS::m_LineThickness, TEXT_ITEM_INFO::m_Text, BOARD_DESIGN_SETTINGS::m_TextItalic, PANEL_FP_EDITOR_DEFAULTS_BASE::m_textItemsGrid, BOARD_DESIGN_SETTINGS::m_TextSize, BOARD_DESIGN_SETTINGS::m_TextThickness, TEXT_ITEM_INFO::m_Visible, ROW_COUNT, ROW_COURTYARD, ROW_EDGES, and SET_MILS_CELL.

Referenced by ResetPanel(), and TransferDataToWindow().

◆ OnAddTextItem()

void PANEL_FP_EDITOR_DEFAULTS::OnAddTextItem ( wxCommandEvent &  event)
overrideprivatevirtual

Reimplemented from PANEL_FP_EDITOR_DEFAULTS_BASE.

Definition at line 388 of file panel_fp_editor_defaults.cpp.

389{
391 return;
392
393 wxGridTableBase* table = m_textItemsGrid->GetTable();
394
395 int newRow = m_textItemsGrid->GetNumberRows();
396 table->AppendRows( 1 );
397 table->SetValueAsBool( newRow, 1, table->GetValueAsBool( newRow - 1, 1 ) );
398 table->SetValueAsLong( newRow, 2, table->GetValueAsLong( newRow - 1, 2 ) );
399
400 m_textItemsGrid->MakeCellVisible( newRow, 0 );
401 m_textItemsGrid->SetGridCursor( newRow, 0 );
402
403 m_textItemsGrid->EnableCellEditControl( true );
404 m_textItemsGrid->ShowCellEditControl();
405}
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:226

References WX_GRID::CommitPendingChanges(), PANEL_FP_EDITOR_DEFAULTS_BASE::m_graphicsGrid, and PANEL_FP_EDITOR_DEFAULTS_BASE::m_textItemsGrid.

◆ OnDeleteTextItem()

void PANEL_FP_EDITOR_DEFAULTS::OnDeleteTextItem ( wxCommandEvent &  event)
overrideprivatevirtual

Reimplemented from PANEL_FP_EDITOR_DEFAULTS_BASE.

Definition at line 408 of file panel_fp_editor_defaults.cpp.

409{
410 wxArrayInt selectedRows = m_textItemsGrid->GetSelectedRows();
411
412 if( selectedRows.empty() && m_textItemsGrid->GetGridCursorRow() >= 0 )
413 selectedRows.push_back( m_textItemsGrid->GetGridCursorRow() );
414
415 if( selectedRows.empty() )
416 return;
417
418 for( int row : selectedRows )
419 {
420 if( row < 2 )
421 {
422 DisplayError( nullptr, _( "Reference and value are mandatory." ) );
423 return;
424 }
425 }
426
428 return;
429
430 // Reverse sort so deleting a row doesn't change the indexes of the other rows.
431 selectedRows.Sort( []( int* first, int* second ) { return *second - *first; } );
432
433 for( int row : selectedRows )
434 {
435 m_textItemsGrid->GetTable()->DeleteRows( row, 1 );
436
437 if( m_textItemsGrid->GetNumberRows() > 0 )
438 {
439 m_textItemsGrid->MakeCellVisible( std::max( 0, row-1 ),
440 m_textItemsGrid->GetGridCursorCol() );
441 m_textItemsGrid->SetGridCursor( std::max( 0, row-1 ),
442 m_textItemsGrid->GetGridCursorCol() );
443 }
444 }
445}
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:280

References _, WX_GRID::CommitPendingChanges(), DisplayError(), PANEL_FP_EDITOR_DEFAULTS_BASE::m_graphicsGrid, and PANEL_FP_EDITOR_DEFAULTS_BASE::m_textItemsGrid.

◆ OnGridSize()

virtual void PANEL_FP_EDITOR_DEFAULTS_BASE::OnGridSize ( wxSizeEvent &  event)
inlineprotectedvirtualinherited

◆ ResetPanel()

void PANEL_FP_EDITOR_DEFAULTS::ResetPanel ( )
overridevirtual

Reset the contents of this panel.

Implements RESETTABLE_PANEL.

Definition at line 448 of file panel_fp_editor_defaults.cpp.

449{
451 cfg.Load(); // Loading without a file will init to defaults
452
453 loadFPSettings( &cfg );
454}
virtual void Load()
Updates the parameters of this object based on the current JSON document contents.
void loadFPSettings(FOOTPRINT_EDITOR_SETTINGS *aCfg)

References JSON_SETTINGS::Load(), and loadFPSettings().

◆ Show()

bool PANEL_FP_EDITOR_DEFAULTS::Show ( bool  aShow)
overrideprivate

Definition at line 295 of file panel_fp_editor_defaults.cpp.

296{
297 bool retVal = wxPanel::Show( aShow );
298
299 if( aShow )
300 {
301 // These *should* work in the constructor, and indeed they do if this panel is the
302 // first displayed. However, on OSX 3.0.5 (at least), if another panel is displayed
303 // first then the icons will be blank unless they're set here.
304 m_bpAdd->SetBitmap( KiBitmap( BITMAPS::small_plus ) );
306 }
307
308 if( aShow && m_firstShow )
309 {
310 m_graphicsGrid->SetColSize( 0, m_graphicsGrid->GetColSize( 0 ) + 1 );
311 m_firstShow = false;
312 }
313
314 return retVal;
315}
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(), PANEL_FP_EDITOR_DEFAULTS_BASE::m_bpAdd, PANEL_FP_EDITOR_DEFAULTS_BASE::m_bpDelete, m_firstShow, PANEL_FP_EDITOR_DEFAULTS_BASE::m_graphicsGrid, small_plus, and small_trash.

◆ TransferDataFromWindow()

bool PANEL_FP_EDITOR_DEFAULTS::TransferDataFromWindow ( )
override

Definition at line 348 of file panel_fp_editor_defaults.cpp.

349{
350 if( !validateData() )
351 return false;
352
353 SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager();
355
356 for( int i = 0; i < ROW_COUNT; ++i )
357 {
359
360 if( i == ROW_EDGES || i == ROW_COURTYARD )
361 continue;
362
363 cfg->m_DesignSettings.m_TextSize[ i ] = wxSize( getGridValue( i, COL_TEXT_WIDTH ),
366
367 wxString msg = m_graphicsGrid->GetCellValue( i, COL_TEXT_ITALIC );
368 cfg->m_DesignSettings.m_TextItalic[ i ] = wxGridCellBoolEditor::IsTrueValue( msg );
369 }
370
371 // Footprint defaults
372 wxGridTableBase* table = m_textItemsGrid->GetTable();
374
375 for( int i = 0; i < m_textItemsGrid->GetNumberRows(); ++i )
376 {
377 wxString text = table->GetValue( i, 0 );
378 bool visible = table->GetValueAsBool( i, 1 );
379 int layer = (int) table->GetValueAsLong( i, 2 );
380
381 cfg->m_DesignSettings.m_DefaultFPTextItems.emplace_back( text, visible, layer );
382 }
383
384 return true;
385}
int getGridValue(int aRow, int aCol)
T * GetAppSettings(bool aLoadNow=true)
Returns a handle to the a given settings by type If the settings have already been loaded,...
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:111

References COL_LINE_THICKNESS, COL_TEXT_HEIGHT, COL_TEXT_ITALIC, COL_TEXT_THICKNESS, COL_TEXT_WIDTH, SETTINGS_MANAGER::GetAppSettings(), getGridValue(), BOARD_DESIGN_SETTINGS::m_DefaultFPTextItems, FOOTPRINT_EDITOR_SETTINGS::m_DesignSettings, PANEL_FP_EDITOR_DEFAULTS_BASE::m_graphicsGrid, BOARD_DESIGN_SETTINGS::m_LineThickness, BOARD_DESIGN_SETTINGS::m_TextItalic, PANEL_FP_EDITOR_DEFAULTS_BASE::m_textItemsGrid, BOARD_DESIGN_SETTINGS::m_TextSize, BOARD_DESIGN_SETTINGS::m_TextThickness, Pgm(), ROW_COUNT, ROW_COURTYARD, ROW_EDGES, text, and validateData().

◆ TransferDataToWindow()

bool PANEL_FP_EDITOR_DEFAULTS::TransferDataToWindow ( )
override

Definition at line 284 of file panel_fp_editor_defaults.cpp.

285{
286 SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager();
288
289 loadFPSettings( cfg );
290
291 return true;
292}

References SETTINGS_MANAGER::GetAppSettings(), loadFPSettings(), and Pgm().

◆ validateData()

bool PANEL_FP_EDITOR_DEFAULTS::validateData ( )
private

Definition at line 324 of file panel_fp_editor_defaults.cpp.

325{
327 return false;
328
329 // Test text parameters.
330 for( int row : { ROW_SILK, ROW_COPPER, ROW_FAB, ROW_OTHERS } )
331 {
332 int textSize = std::min( getGridValue( row, COL_TEXT_WIDTH ),
334
335 if( getGridValue( row, COL_TEXT_THICKNESS ) > textSize / 4 )
336 {
337 wxString msg = _( "Text will not be readable with a thickness greater than\n"
338 "1/4 its width or height." );
340 return false;
341 }
342 }
343
344 return true;
345}
void SetError(const wxString &aMessage, const wxString &aPageName, int aCtrlId, int aRow=-1, int aCol=-1)

References _, COL_TEXT_HEIGHT, COL_TEXT_THICKNESS, COL_TEXT_WIDTH, WX_GRID::CommitPendingChanges(), getGridValue(), PANEL_FP_EDITOR_DEFAULTS_BASE::m_graphicsGrid, m_parent, PANEL_FP_EDITOR_DEFAULTS_BASE::m_textItemsGrid, ROW_COPPER, ROW_FAB, ROW_OTHERS, ROW_SILK, and PAGED_DIALOG::SetError().

Referenced by TransferDataFromWindow().

Member Data Documentation

◆ defaultTextItemsLabel

wxStaticText* PANEL_FP_EDITOR_DEFAULTS_BASE::defaultTextItemsLabel
protectedinherited

◆ m_bpAdd

wxBitmapButton* PANEL_FP_EDITOR_DEFAULTS_BASE::m_bpAdd
protectedinherited

◆ m_bpDelete

wxBitmapButton* PANEL_FP_EDITOR_DEFAULTS_BASE::m_bpDelete
protectedinherited

◆ m_firstShow

bool PANEL_FP_EDITOR_DEFAULTS::m_firstShow = true
private

Definition at line 55 of file panel_fp_editor_defaults.h.

Referenced by Show().

◆ m_graphicsGrid

◆ m_parent

PAGED_DIALOG* PANEL_FP_EDITOR_DEFAULTS::m_parent
private

Definition at line 54 of file panel_fp_editor_defaults.h.

Referenced by PANEL_FP_EDITOR_DEFAULTS(), and validateData().

◆ m_staticTextInfo

wxStaticText* PANEL_FP_EDITOR_DEFAULTS_BASE::m_staticTextInfo
protectedinherited

◆ m_textItemsGrid

◆ m_units

EDA_UNITS PANEL_FP_EDITOR_DEFAULTS::m_units = EDA_UNITS::MILLIMETRES
private

Definition at line 53 of file panel_fp_editor_defaults.h.

Referenced by getGridValue(), and PANEL_FP_EDITOR_DEFAULTS().


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