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

Public Member Functions

 PANEL_FP_EDITOR_DEFAULTS (FOOTPRINT_EDIT_FRAME *aFrame, PAGED_DIALOG *aParent)
 
 ~PANEL_FP_EDITOR_DEFAULTS () override
 

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 ()
 
bool TransferDataToWindow () override
 
bool TransferDataFromWindow () override
 

Private Attributes

BOARD_DESIGN_SETTINGS m_brdSettings
 
FOOTPRINT_EDIT_FRAMEm_frame
 
PAGED_DIALOGm_parent
 
bool m_firstShow = true
 

Detailed Description

Definition at line 30 of file panel_fp_editor_defaults.h.

Constructor & Destructor Documentation

◆ PANEL_FP_EDITOR_DEFAULTS()

PANEL_FP_EDITOR_DEFAULTS::PANEL_FP_EDITOR_DEFAULTS ( FOOTPRINT_EDIT_FRAME aFrame,
PAGED_DIALOG aParent 
)

Definition at line 173 of file panel_fp_editor_defaults.cpp.

174  :
176  m_brdSettings( aFrame->GetDesignSettings() ),
177  m_frame( aFrame ),
178  m_parent( aParent )
179 {
180  m_textItemsGrid->SetDefaultRowSize( m_textItemsGrid->GetDefaultRowSize() + 4 );
181  m_graphicsGrid->SetDefaultRowSize( m_graphicsGrid->GetDefaultRowSize() + 4 );
182 
184  m_textItemsGrid->PushEventHandler( new GRID_TRICKS( m_textItemsGrid ) );
185  m_textItemsGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
186 
187  wxGridCellAttr* attr = new wxGridCellAttr;
188  attr->SetRenderer( new wxGridCellBoolRenderer() );
189  attr->SetReadOnly(); // not really; we delegate interactivity to GRID_TRICKS
190  attr->SetAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
191  m_textItemsGrid->SetColAttr( 1, attr );
192 
193  attr = new wxGridCellAttr;
194  attr->SetRenderer( new GRID_CELL_LAYER_RENDERER( m_frame ) );
195  attr->SetEditor( new GRID_CELL_LAYER_SELECTOR( m_frame, {} ) );
196  m_textItemsGrid->SetColAttr( 2, attr );
197 
198  // Work around a bug in wxWidgets where it fails to recalculate the grid height
199  // after changing the default row size
200  m_graphicsGrid->AppendRows( 1 );
201  m_graphicsGrid->DeleteRows( m_graphicsGrid->GetNumberRows() - 1, 1 );
202 
203  m_graphicsGrid->PushEventHandler( new GRID_TRICKS( m_graphicsGrid ) );
204 
205  m_staticTextInfo->SetFont( KIUI::GetInfoFont( this ).Italic() );
206 }
BOARD_DESIGN_SETTINGS & GetDesignSettings() const override
Returns the BOARD_DESIGN_SETTINGS for the open project.
wxFont GetInfoFont(wxWindow *aWindow)
Definition: ui_common.cpp:144
Add mouse and command handling (such as cut, copy, and paste) to a WX_GRID instance.
Definition: grid_tricks.h:55
BOARD_DESIGN_SETTINGS m_brdSettings
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
wxTreebook * GetTreebook()
Definition: paged_dialog.h:37
FOOTPRINT_EDIT_FRAME * m_frame
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)

References KIUI::GetInfoFont(), m_frame, PANEL_FP_EDITOR_DEFAULTS_BASE::m_graphicsGrid, PANEL_FP_EDITOR_DEFAULTS_BASE::m_staticTextInfo, PANEL_FP_EDITOR_DEFAULTS_BASE::m_textItemsGrid, and WX_GRID::SetTable().

◆ ~PANEL_FP_EDITOR_DEFAULTS()

PANEL_FP_EDITOR_DEFAULTS::~PANEL_FP_EDITOR_DEFAULTS ( )
override

Definition at line 209 of file panel_fp_editor_defaults.cpp.

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

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 307 of file panel_fp_editor_defaults.cpp.

308 {
310  m_graphicsGrid->GetCellValue( aRow, aCol ) );
311 }
long long int ValueFromString(EDA_UNITS aUnits, const wxString &aTextValue, EDA_DATA_TYPE aType)
Function ValueFromString converts aTextValue in aUnits to internal units used by the application.
Definition: base_units.cpp:416
FOOTPRINT_EDIT_FRAME * m_frame
EDA_UNITS GetUserUnits() const
Return the user units currently in use.

References EDA_BASE_FRAME::GetUserUnits(), m_frame, PANEL_FP_EDITOR_DEFAULTS_BASE::m_graphicsGrid, and ValueFromString().

Referenced by TransferDataFromWindow(), and validateData().

◆ OnAddTextItem()

void PANEL_FP_EDITOR_DEFAULTS::OnAddTextItem ( wxCommandEvent &  event)
overrideprivatevirtual

Reimplemented from PANEL_FP_EDITOR_DEFAULTS_BASE.

Definition at line 380 of file panel_fp_editor_defaults.cpp.

381 {
383  return;
384 
385  wxGridTableBase* table = m_textItemsGrid->GetTable();
386 
387  int newRow = m_textItemsGrid->GetNumberRows();
388  table->AppendRows( 1 );
389  table->SetValueAsBool( newRow, 1, table->GetValueAsBool( newRow - 1, 1 ) );
390  table->SetValueAsLong( newRow, 2, table->GetValueAsLong( newRow - 1, 2 ) );
391 
392  m_textItemsGrid->MakeCellVisible( newRow, 0 );
393  m_textItemsGrid->SetGridCursor( newRow, 0 );
394 
395  m_textItemsGrid->EnableCellEditControl( true );
396  m_textItemsGrid->ShowCellEditControl();
397 }
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 400 of file panel_fp_editor_defaults.cpp.

401 {
402  wxArrayInt selectedRows = m_textItemsGrid->GetSelectedRows();
403 
404  if( selectedRows.empty() && m_textItemsGrid->GetGridCursorRow() >= 0 )
405  selectedRows.push_back( m_textItemsGrid->GetGridCursorRow() );
406 
407  if( selectedRows.empty() )
408  return;
409 
410  for( int row : selectedRows )
411  {
412  if( row < 2 )
413  {
414  DisplayError( nullptr, _( "Reference and value are mandatory." ) );
415  return;
416  }
417  }
418 
420  return;
421 
422  // Reverse sort so deleting a row doesn't change the indexes of the other rows.
423  selectedRows.Sort( []( int* first, int* second ) { return *second - *first; } );
424 
425  for( int row : selectedRows )
426  {
427  m_textItemsGrid->GetTable()->DeleteRows( row, 1 );
428 
429  if( m_textItemsGrid->GetNumberRows() > 0 )
430  {
431  m_textItemsGrid->MakeCellVisible( std::max( 0, row-1 ),
432  m_textItemsGrid->GetGridCursorCol() );
433  m_textItemsGrid->SetGridCursor( std::max( 0, row-1 ),
434  m_textItemsGrid->GetGridCursorCol() );
435  }
436  }
437 }
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:279
#define _(s)
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:226

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

◆ Show()

bool PANEL_FP_EDITOR_DEFAULTS::Show ( bool  aShow)
overrideprivate

Definition at line 284 of file panel_fp_editor_defaults.cpp.

285 {
286  bool retVal = wxPanel::Show( aShow );
287 
288  if( aShow )
289  {
290  // These *should* work in the constructor, and indeed they do if this panel is the
291  // first displayed. However, on OSX 3.0.5 (at least), if another panel is displayed
292  // first then the icons will be blank unless they're set here.
293  m_bpAdd->SetBitmap( KiBitmap( BITMAPS::small_plus ) );
294  m_bpDelete->SetBitmap( KiBitmap( BITMAPS::small_trash ) );
295  }
296 
297  if( aShow && m_firstShow )
298  {
299  m_graphicsGrid->SetColSize( 0, m_graphicsGrid->GetColSize( 0 ) + 1 );
300  m_firstShow = false;
301  }
302 
303  return retVal;
304 }
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 ( )
overrideprivate

Definition at line 338 of file panel_fp_editor_defaults.cpp.

339 {
340  if( !validateData() )
341  return false;
342 
343  for( int i = 0; i < ROW_COUNT; ++i )
344  {
346 
347  if( i == ROW_EDGES || i == ROW_COURTYARD )
348  continue;
349 
353 
354  wxString msg = m_graphicsGrid->GetCellValue( i, COL_TEXT_ITALIC );
355  m_brdSettings.m_TextItalic[ i ] = wxGridCellBoolEditor::IsTrueValue( msg );
356  }
357 
358  // Footprint defaults
359  wxGridTableBase* table = m_textItemsGrid->GetTable();
361 
362  for( int i = 0; i < m_textItemsGrid->GetNumberRows(); ++i )
363  {
364  wxString text = table->GetValue( i, 0 );
365  bool visible = table->GetValueAsBool( i, 1 );
366  int layer = (int) table->GetValueAsLong( i, 2 );
367 
368  m_brdSettings.m_DefaultFPTextItems.emplace_back( text, visible, layer );
369  }
370 
372 
374  cfg->m_DesignSettings = m_brdSettings;
375 
376  return true;
377 }
std::vector< TEXT_ITEM_INFO > m_DefaultFPTextItems
BOARD_DESIGN_SETTINGS & GetDesignSettings() const override
Returns the BOARD_DESIGN_SETTINGS for the open project.
BOARD_DESIGN_SETTINGS m_brdSettings
wxSize m_TextSize[LAYER_CLASS_COUNT]
int m_TextThickness[LAYER_CLASS_COUNT]
bool m_TextItalic[LAYER_CLASS_COUNT]
int m_LineThickness[LAYER_CLASS_COUNT]
int getGridValue(int aRow, int aCol)
FOOTPRINT_EDITOR_SETTINGS * GetSettings()
FOOTPRINT_EDIT_FRAME * m_frame

References COL_LINE_THICKNESS, COL_TEXT_HEIGHT, COL_TEXT_ITALIC, COL_TEXT_THICKNESS, COL_TEXT_WIDTH, FOOTPRINT_EDIT_FRAME::GetDesignSettings(), getGridValue(), FOOTPRINT_EDIT_FRAME::GetSettings(), m_brdSettings, BOARD_DESIGN_SETTINGS::m_DefaultFPTextItems, m_frame, 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, ROW_COUNT, ROW_COURTYARD, ROW_EDGES, text, and validateData().

◆ TransferDataToWindow()

bool PANEL_FP_EDITOR_DEFAULTS::TransferDataToWindow ( )
overrideprivate

Definition at line 217 of file panel_fp_editor_defaults.cpp.

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

◆ validateData()

bool PANEL_FP_EDITOR_DEFAULTS::validateData ( )
private

Definition at line 314 of file panel_fp_editor_defaults.cpp.

315 {
317  return false;
318 
319  // Test text parameters.
320  for( int row : { ROW_SILK, ROW_COPPER, ROW_FAB, ROW_OTHERS } )
321  {
322  int textSize = std::min( getGridValue( row, COL_TEXT_WIDTH ),
323  getGridValue( row, COL_TEXT_HEIGHT ) );
324 
325  if( getGridValue( row, COL_TEXT_THICKNESS ) > textSize / 4 )
326  {
327  wxString msg = _( "Text will not be readable with a thickness greater than\n"
328  "1/4 its width or height." );
329  m_parent->SetError( msg, this, m_graphicsGrid, row, COL_TEXT_THICKNESS );
330  return false;
331  }
332  }
333 
334  return true;
335 }
void SetError(const wxString &aMessage, const wxString &aPageName, int aCtrlId, int aRow=-1, int aCol=-1)
#define _(s)
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:226
int getGridValue(int aRow, int aCol)

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_brdSettings

BOARD_DESIGN_SETTINGS PANEL_FP_EDITOR_DEFAULTS::m_brdSettings
private

Definition at line 49 of file panel_fp_editor_defaults.h.

Referenced by TransferDataFromWindow(), and TransferDataToWindow().

◆ m_firstShow

bool PANEL_FP_EDITOR_DEFAULTS::m_firstShow = true
private

Definition at line 52 of file panel_fp_editor_defaults.h.

Referenced by Show().

◆ m_frame

FOOTPRINT_EDIT_FRAME* PANEL_FP_EDITOR_DEFAULTS::m_frame
private

◆ m_graphicsGrid

◆ m_parent

PAGED_DIALOG* PANEL_FP_EDITOR_DEFAULTS::m_parent
private

Definition at line 51 of file panel_fp_editor_defaults.h.

Referenced by validateData().

◆ m_staticTextInfo

wxStaticText* PANEL_FP_EDITOR_DEFAULTS_BASE::m_staticTextInfo
protectedinherited

◆ m_textItemsGrid


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