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

173  :
175  m_brdSettings( aFrame->GetDesignSettings() ),
176  m_frame( aFrame ),
177  m_parent( aParent )
178 {
179  m_textItemsGrid->SetDefaultRowSize( m_textItemsGrid->GetDefaultRowSize() + 4 );
180  m_graphicsGrid->SetDefaultRowSize( m_graphicsGrid->GetDefaultRowSize() + 4 );
181 
183  m_textItemsGrid->PushEventHandler( new GRID_TRICKS( m_textItemsGrid ) );
184 
185  wxGridCellAttr* attr = new wxGridCellAttr;
186  attr->SetRenderer( new wxGridCellBoolRenderer() );
187  attr->SetReadOnly(); // not really; we delegate interactivity to GRID_TRICKS
188  attr->SetAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
189  m_textItemsGrid->SetColAttr( 1, attr );
190 
191  attr = new wxGridCellAttr;
192  attr->SetRenderer( new GRID_CELL_LAYER_RENDERER( m_frame ) );
193  attr->SetEditor( new GRID_CELL_LAYER_SELECTOR( m_frame, {} ) );
194  m_textItemsGrid->SetColAttr( 2, attr );
195 
196  // Work around a bug in wxWidgets where it fails to recalculate the grid height
197  // after changing the default row size
198  m_graphicsGrid->AppendRows( 1 );
199  m_graphicsGrid->DeleteRows( m_graphicsGrid->GetNumberRows() - 1, 1 );
200 
201  m_graphicsGrid->PushEventHandler( new GRID_TRICKS( m_graphicsGrid ) );
202 
203  m_staticTextInfo->SetFont( KIUI::GetInfoFont( this ).Italic() );
204 }
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:72
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 207 of file panel_fp_editor_defaults.cpp.

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

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

306 {
308  m_graphicsGrid->GetCellValue( aRow, aCol ) );
309 }
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 378 of file panel_fp_editor_defaults.cpp.

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

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

399 {
401  return;
402 
403  int curRow = m_textItemsGrid->GetGridCursorRow();
404 
405  if( curRow < 2 ) // First two rows are required
406  return;
407 
408  m_textItemsGrid->GetTable()->DeleteRows( curRow, 1 );
409 
410  curRow = std::max( 0, curRow - 1 );
411  m_textItemsGrid->MakeCellVisible( curRow, m_textItemsGrid->GetGridCursorCol() );
412  m_textItemsGrid->SetGridCursor( curRow, m_textItemsGrid->GetGridCursorCol() );
413 }
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:190

References WX_GRID::CommitPendingChanges(), 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 282 of file panel_fp_editor_defaults.cpp.

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

337 {
338  if( !validateData() )
339  return false;
340 
341  for( int i = 0; i < ROW_COUNT; ++i )
342  {
344 
345  if( i == ROW_EDGES || i == ROW_COURTYARD )
346  continue;
347 
351 
352  wxString msg = m_graphicsGrid->GetCellValue( i, COL_TEXT_ITALIC );
353  m_brdSettings.m_TextItalic[ i ] = wxGridCellBoolEditor::IsTrueValue( msg );
354  }
355 
356  // Footprint defaults
357  wxGridTableBase* table = m_textItemsGrid->GetTable();
359 
360  for( int i = 0; i < m_textItemsGrid->GetNumberRows(); ++i )
361  {
362  wxString text = table->GetValue( i, 0 );
363  bool visible = table->GetValueAsBool( i, 1 );
364  int layer = (int) table->GetValueAsLong( i, 2 );
365 
366  m_brdSettings.m_DefaultFPTextItems.emplace_back( text, visible, layer );
367  }
368 
370 
372  cfg->m_DesignSettings = m_brdSettings;
373 
374  return true;
375 }
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 215 of file panel_fp_editor_defaults.cpp.

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

313 {
315  return false;
316 
317  // Test text parameters.
318  for( int row : { ROW_SILK, ROW_COPPER, ROW_FAB, ROW_OTHERS } )
319  {
320  int textSize = std::min( getGridValue( row, COL_TEXT_WIDTH ),
321  getGridValue( row, COL_TEXT_HEIGHT ) );
322 
323  if( getGridValue( row, COL_TEXT_THICKNESS ) > textSize / 4 )
324  {
325  wxString msg = _( "Text will not be readable with a thickness greater than\n"
326  "1/4 its width or height." );
327  m_parent->SetError( msg, this, m_graphicsGrid, row, COL_TEXT_THICKNESS );
328  return false;
329  }
330  }
331 
332  return true;
333 }
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:190
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: