KiCad PCB EDA Suite
PANEL_MODEDIT_DEFAULTS Class Reference

#include <panel_modedit_defaults.h>

Inheritance diagram for PANEL_MODEDIT_DEFAULTS:
PANEL_MODEDIT_DEFAULTS_BASE

Public Member Functions

 PANEL_MODEDIT_DEFAULTS (FOOTPRINT_EDIT_FRAME *aFrame, PAGED_DIALOG *aParent)
 
 ~PANEL_MODEDIT_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_layerClassesGrid
 

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_modedit_defaults.h.

Constructor & Destructor Documentation

◆ PANEL_MODEDIT_DEFAULTS()

PANEL_MODEDIT_DEFAULTS::PANEL_MODEDIT_DEFAULTS ( FOOTPRINT_EDIT_FRAME aFrame,
PAGED_DIALOG aParent 
)

Definition at line 171 of file panel_modedit_defaults.cpp.

171  :
173  m_brdSettings( aFrame->GetDesignSettings() ),
174  m_frame( aFrame ),
175  m_Parent( aParent )
176 {
177  m_textItemsGrid->SetDefaultRowSize( m_textItemsGrid->GetDefaultRowSize() + 4 );
178  m_layerClassesGrid->SetDefaultRowSize( m_layerClassesGrid->GetDefaultRowSize() + 4 );
179 
181 
182  wxGridCellAttr* attr = new wxGridCellAttr;
183  attr->SetRenderer( new wxGridCellBoolRenderer() );
184  attr->SetReadOnly(); // not really; we delegate interactivity to GRID_TRICKS
185  m_textItemsGrid->SetColAttr( 1, attr );
186 
187  attr = new wxGridCellAttr;
188  attr->SetRenderer( new GRID_CELL_LAYER_RENDERER( m_frame ) );
189  attr->SetEditor( new GRID_CELL_LAYER_SELECTOR( m_frame, LSET::ForbiddenTextLayers() ) );
190  m_textItemsGrid->SetColAttr( 2, attr );
191 
192  // Work around a bug in wxWidgets where it fails to recalculate the grid height
193  // after changing the default row size
194  m_layerClassesGrid->AppendRows( 1 );
195  m_layerClassesGrid->DeleteRows( m_layerClassesGrid->GetNumberRows() - 1, 1 );
196 
197  m_layerClassesGrid->PushEventHandler( new GRID_TRICKS( m_layerClassesGrid ) );
198 
199  wxFont infoFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
200  infoFont.SetSymbolicSize( wxFONTSIZE_SMALL );
201  m_staticTextInfo->SetFont( infoFont );
202 }
BOARD_DESIGN_SETTINGS & GetDesignSettings() const override
Returns the BOARD_DESIGN_SETTINGS for the open project Overloaded in FOOTPRINT_EDIT_FRAME.
BOARD_DESIGN_SETTINGS m_brdSettings
PANEL_MODEDIT_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)
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
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:59
wxTreebook * GetTreebook()
Definition: paged_dialog.h:45
static LSET ForbiddenTextLayers()
Function ForbiddenTextLayers Layers which are now allowed to have text on them.
Definition: lset.cpp:832
FOOTPRINT_EDIT_FRAME * m_frame

References LSET::ForbiddenTextLayers(), m_frame, PANEL_MODEDIT_DEFAULTS_BASE::m_layerClassesGrid, PANEL_MODEDIT_DEFAULTS_BASE::m_staticTextInfo, PANEL_MODEDIT_DEFAULTS_BASE::m_textItemsGrid, and WX_GRID::SetTable().

◆ ~PANEL_MODEDIT_DEFAULTS()

PANEL_MODEDIT_DEFAULTS::~PANEL_MODEDIT_DEFAULTS ( )
override

Definition at line 205 of file panel_modedit_defaults.cpp.

206 {
207  // destroy GRID_TRICKS before m_layerClassesGrid.
208  m_layerClassesGrid->PopEventHandler( true );
209 }

References PANEL_MODEDIT_DEFAULTS_BASE::m_layerClassesGrid.

Member Function Documentation

◆ getGridValue()

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

Definition at line 301 of file panel_modedit_defaults.cpp.

302 {
304  m_layerClassesGrid->GetCellValue( aRow, aCol ), true );
305 }
EDA_UNITS GetUserUnits() const
Return the user units currently in use.
long long int ValueFromString(EDA_UNITS aUnits, const wxString &aTextValue, bool aUseMils, EDA_DATA_TYPE aType)
Function ValueFromString converts aTextValue in aUnits to internal units used by the application.
Definition: base_units.cpp:471
FOOTPRINT_EDIT_FRAME * m_frame

References EDA_BASE_FRAME::GetUserUnits(), m_frame, PANEL_MODEDIT_DEFAULTS_BASE::m_layerClassesGrid, and ValueFromString().

Referenced by TransferDataFromWindow(), and validateData().

◆ OnAddTextItem()

void PANEL_MODEDIT_DEFAULTS::OnAddTextItem ( wxCommandEvent &  event)
overrideprivatevirtual

Reimplemented from PANEL_MODEDIT_DEFAULTS_BASE.

Definition at line 372 of file panel_modedit_defaults.cpp.

373 {
375  return;
376 
377  wxGridTableBase* table = m_textItemsGrid->GetTable();
378 
379  int newRow = m_textItemsGrid->GetNumberRows();
380  table->AppendRows( 1 );
381  table->SetValueAsBool( newRow, 1, table->GetValueAsBool( newRow - 1, 1 ) );
382  table->SetValueAsLong( newRow, 2, table->GetValueAsLong( newRow - 1, 2 ) );
383 
384  m_textItemsGrid->MakeCellVisible( newRow, 0 );
385  m_textItemsGrid->SetGridCursor( newRow, 0 );
386 
387  m_textItemsGrid->EnableCellEditControl( true );
388  m_textItemsGrid->ShowCellEditControl();
389 }
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:174

References WX_GRID::CommitPendingChanges(), PANEL_MODEDIT_DEFAULTS_BASE::m_layerClassesGrid, and PANEL_MODEDIT_DEFAULTS_BASE::m_textItemsGrid.

◆ OnDeleteTextItem()

void PANEL_MODEDIT_DEFAULTS::OnDeleteTextItem ( wxCommandEvent &  event)
overrideprivatevirtual

Reimplemented from PANEL_MODEDIT_DEFAULTS_BASE.

Definition at line 392 of file panel_modedit_defaults.cpp.

393 {
395  return;
396 
397  int curRow = m_textItemsGrid->GetGridCursorRow();
398 
399  if( curRow < 2 ) // First two rows are required
400  return;
401 
402  m_textItemsGrid->GetTable()->DeleteRows( curRow, 1 );
403 
404  curRow = std::max( 0, curRow - 1 );
405  m_textItemsGrid->MakeCellVisible( curRow, m_textItemsGrid->GetGridCursorCol() );
406  m_textItemsGrid->SetGridCursor( curRow, m_textItemsGrid->GetGridCursorCol() );
407 }
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:174

References WX_GRID::CommitPendingChanges(), PANEL_MODEDIT_DEFAULTS_BASE::m_layerClassesGrid, and PANEL_MODEDIT_DEFAULTS_BASE::m_textItemsGrid.

◆ OnGridSize()

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

◆ Show()

bool PANEL_MODEDIT_DEFAULTS::Show ( bool  aShow)
overrideprivate

Definition at line 278 of file panel_modedit_defaults.cpp.

279 {
280  bool retVal = wxPanel::Show( aShow );
281 
282  if( aShow )
283  {
284  // These *should* work in the constructor, and indeed they do if this panel is the
285  // first displayed. However, on OSX 3.0.5 (at least), if another panel is displayed
286  // first then the icons will be blank unless they're set here.
287  m_bpAdd->SetBitmap( KiBitmap( small_plus_xpm ) );
288  m_bpDelete->SetBitmap( KiBitmap( trash_xpm ) );
289  }
290 
291  if( aShow && m_firstShow )
292  {
293  m_layerClassesGrid->SetColSize( 0, m_layerClassesGrid->GetColSize( 0 ) + 1 );
294  m_firstShow = false;
295  }
296 
297  return retVal;
298 }
const BITMAP_OPAQUE trash_xpm[1]
Definition: trash.cpp:46
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_plus_xpm[1]
Definition: small_plus.cpp:20

References KiBitmap(), PANEL_MODEDIT_DEFAULTS_BASE::m_bpAdd, PANEL_MODEDIT_DEFAULTS_BASE::m_bpDelete, m_firstShow, PANEL_MODEDIT_DEFAULTS_BASE::m_layerClassesGrid, small_plus_xpm, and trash_xpm.

◆ TransferDataFromWindow()

bool PANEL_MODEDIT_DEFAULTS::TransferDataFromWindow ( )
overrideprivate

Definition at line 332 of file panel_modedit_defaults.cpp.

333 {
334  if( !validateData() )
335  return false;
336 
337  for( int i = 0; i < ROW_COUNT; ++i )
338  {
340 
341  if( i == ROW_EDGES || i == ROW_COURTYARD )
342  continue;
343 
347 
348  wxString msg = m_layerClassesGrid->GetCellValue( i, COL_TEXT_ITALIC );
349  m_brdSettings.m_TextItalic[ i ] = wxGridCellBoolEditor::IsTrueValue( msg );
350  }
351 
352  // Footprint defaults
353  wxGridTableBase* table = m_textItemsGrid->GetTable();
355 
356  for( int i = 0; i < m_textItemsGrid->GetNumberRows(); ++i )
357  {
358  wxString text = table->GetValue( i, 0 );
359  bool visible = table->GetValueAsBool( i, 1 );
360  int layer = (int) table->GetValueAsLong( i, 2 );
361 
362  m_brdSettings.m_DefaultFPTextItems.emplace_back( text, visible, layer );
363  }
364 
366  cfg->m_DesignSettings = m_brdSettings;
367 
368  return true;
369 }
std::vector< TEXT_ITEM_INFO > m_DefaultFPTextItems
int getGridValue(int aRow, int aCol)
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]
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, getGridValue(), FOOTPRINT_EDIT_FRAME::GetSettings(), m_brdSettings, BOARD_DESIGN_SETTINGS::m_DefaultFPTextItems, m_frame, PANEL_MODEDIT_DEFAULTS_BASE::m_layerClassesGrid, BOARD_DESIGN_SETTINGS::m_LineThickness, BOARD_DESIGN_SETTINGS::m_TextItalic, PANEL_MODEDIT_DEFAULTS_BASE::m_textItemsGrid, BOARD_DESIGN_SETTINGS::m_TextSize, BOARD_DESIGN_SETTINGS::m_TextThickness, ROW_COUNT, ROW_COURTYARD, ROW_EDGES, and validateData().

◆ TransferDataToWindow()

bool PANEL_MODEDIT_DEFAULTS::TransferDataToWindow ( )
overrideprivate

Definition at line 212 of file panel_modedit_defaults.cpp.

213 {
214  wxColour disabledColour = wxSystemSettings::GetColour( wxSYS_COLOUR_BACKGROUND );
215 
216 #define SET_MILS_CELL( row, col, val ) \
217  m_layerClassesGrid->SetCellValue( row, col, StringFromValue( m_frame->GetUserUnits(), val, true, true ) )
218 
219 #define DISABLE_CELL( row, col ) \
220  m_layerClassesGrid->SetReadOnly( row, col ); m_layerClassesGrid->SetCellBackgroundColour( row, col, disabledColour );
221 
222  for( int i = 0; i < ROW_COUNT; ++i )
223  {
225 
226  if( i == ROW_EDGES || i == ROW_COURTYARD )
227  {
232  }
233  else
234  {
238  m_layerClassesGrid->SetCellValue( i, COL_TEXT_ITALIC, m_brdSettings.m_TextItalic[ i ] ? "1" : "" );
239 
240  auto attr = new wxGridCellAttr;
241  attr->SetRenderer( new wxGridCellBoolRenderer() );
242  attr->SetReadOnly(); // not really; we delegate interactivity to GRID_TRICKS
243  attr->SetAlignment( wxALIGN_CENTER, wxALIGN_BOTTOM );
244  m_layerClassesGrid->SetAttr( i, COL_TEXT_ITALIC, attr );
245  }
246  }
247 
248  // Footprint defaults
249  m_textItemsGrid->GetTable()->AppendRows( m_brdSettings.m_DefaultFPTextItems.size() );
250 
251  for( size_t i = 0; i < m_brdSettings.m_DefaultFPTextItems.size(); ++i )
252  {
254 
255  m_textItemsGrid->GetTable()->SetValue( i, 0, item.m_Text );
256  m_textItemsGrid->GetTable()->SetValueAsBool( i, 1, item.m_Visible );
257  m_textItemsGrid->GetTable()->SetValueAsLong( i, 2, item.m_Layer );
258  }
259 
260  for( int col = 0; col < m_layerClassesGrid->GetNumberCols(); col++ )
261  {
262  // Set the minimal width to the column label size.
263  m_layerClassesGrid->SetColMinimalWidth( col, m_layerClassesGrid->GetVisibleWidth( col, true, false, false ) );
264 
265  // Set the width to see the full contents
266  if( m_layerClassesGrid->IsColShown( col ) )
267  m_layerClassesGrid->SetColSize( col, m_layerClassesGrid->GetVisibleWidth( col, true, true, true ) );
268  }
269 
270  m_layerClassesGrid->SetRowLabelSize( m_layerClassesGrid->GetVisibleWidth( -1, true, true, true ) );
271 
272  Layout();
273 
274  return true;
275 }
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:230
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, TEXT_ITEM_INFO::m_Layer, PANEL_MODEDIT_DEFAULTS_BASE::m_layerClassesGrid, BOARD_DESIGN_SETTINGS::m_LineThickness, TEXT_ITEM_INFO::m_Text, BOARD_DESIGN_SETTINGS::m_TextItalic, PANEL_MODEDIT_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_MODEDIT_DEFAULTS::validateData ( )
private

Definition at line 308 of file panel_modedit_defaults.cpp.

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

References _, COL_TEXT_HEIGHT, COL_TEXT_THICKNESS, COL_TEXT_WIDTH, WX_GRID::CommitPendingChanges(), getGridValue(), PANEL_MODEDIT_DEFAULTS_BASE::m_layerClassesGrid, m_Parent, PANEL_MODEDIT_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_MODEDIT_DEFAULTS_BASE::defaultTextItemsLabel
protectedinherited

◆ m_bpAdd

wxBitmapButton* PANEL_MODEDIT_DEFAULTS_BASE::m_bpAdd
protectedinherited

◆ m_bpDelete

wxBitmapButton* PANEL_MODEDIT_DEFAULTS_BASE::m_bpDelete
protectedinherited

◆ m_brdSettings

BOARD_DESIGN_SETTINGS PANEL_MODEDIT_DEFAULTS::m_brdSettings
private

Definition at line 32 of file panel_modedit_defaults.h.

Referenced by TransferDataFromWindow(), and TransferDataToWindow().

◆ m_firstShow

bool PANEL_MODEDIT_DEFAULTS::m_firstShow = true
private

Definition at line 35 of file panel_modedit_defaults.h.

Referenced by Show().

◆ m_frame

FOOTPRINT_EDIT_FRAME* PANEL_MODEDIT_DEFAULTS::m_frame
private

◆ m_layerClassesGrid

◆ m_Parent

PAGED_DIALOG* PANEL_MODEDIT_DEFAULTS::m_Parent
private

Definition at line 34 of file panel_modedit_defaults.h.

Referenced by validateData().

◆ m_staticTextInfo

wxStaticText* PANEL_MODEDIT_DEFAULTS_BASE::m_staticTextInfo
protectedinherited

◆ m_textItemsGrid


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