KiCad PCB EDA Suite
PANEL_SETUP_TEXT_AND_GRAPHICS Class Reference

#include <panel_setup_text_and_graphics.h>

Inheritance diagram for PANEL_SETUP_TEXT_AND_GRAPHICS:
PANEL_SETUP_TEXT_AND_GRAPHICS_BASE

Public Member Functions

 PANEL_SETUP_TEXT_AND_GRAPHICS (PAGED_DIALOG *aParent, PCB_EDIT_FRAME *aFrame)
 
 ~PANEL_SETUP_TEXT_AND_GRAPHICS () override
 
bool TransferDataToWindow () override
 
bool TransferDataFromWindow () override
 
void ImportSettingsFrom (BOARD *aBoard)
 

Protected Attributes

wxBoxSizer * m_gridSizer
 
wxStaticText * m_staticTextDefProp
 
WX_GRIDm_grid
 
wxStaticText * m_staticTextDefPropDim
 
wxPanel * m_panel1
 
wxStaticText * m_lblDimensionUnits
 
wxChoice * m_dimensionUnits
 
wxStaticText * m_lblTextPositionMode
 
wxChoice * m_dimensionTextPositionMode
 
wxStaticText * m_lblDimensionUnitsFormat
 
wxChoice * m_dimensionUnitsFormat
 
wxCheckBox * m_dimensionTextKeepAligned
 
wxStaticText * m_lblDimensionPrecision
 
wxChoice * m_dimensionPrecision
 
wxStaticText * m_lblArrowLength
 
wxTextCtrl * m_dimensionArrowLength
 
wxStaticText * m_arrowLengthUnits
 
wxCheckBox * m_dimensionSuppressZeroes
 
wxStaticText * m_lblExtensionOffset
 
wxTextCtrl * m_dimensionExtensionOffset
 
wxStaticText * m_dimensionExtensionOffsetUnits
 

Private Member Functions

int getGridValue (int aRow, int aCol)
 
void onUnitsChanged (wxCommandEvent &aEvent)
 

Private Attributes

PAGED_DIALOGm_Parent
 
PCB_EDIT_FRAMEm_Frame
 
BOARD_DESIGN_SETTINGSm_BrdSettings
 
UNIT_BINDER m_arrowLength
 
UNIT_BINDER m_extensionOffset
 

Detailed Description

Definition at line 38 of file panel_setup_text_and_graphics.h.

Constructor & Destructor Documentation

◆ PANEL_SETUP_TEXT_AND_GRAPHICS()

PANEL_SETUP_TEXT_AND_GRAPHICS::PANEL_SETUP_TEXT_AND_GRAPHICS ( PAGED_DIALOG aParent,
PCB_EDIT_FRAME aFrame 
)

Definition at line 58 of file panel_setup_text_and_graphics.cpp.

59  :
64 {
65  m_Parent = aParent;
66  m_Frame = aFrame;
68 
69  m_grid->SetDefaultRowSize( m_grid->GetDefaultRowSize() + 4 );
70 
71  // Work around a bug in wxWidgets where it fails to recalculate the grid height
72  // after changing the default row size
73  m_grid->AppendRows( 1 );
74  m_grid->DeleteRows( m_grid->GetNumberRows() - 1, 1 );
75 
76  // Gives a suitable size to m_grid columns
77  // The default wxWidget col size is not very good
78  // Calculate a min best size to handle longest usual numeric values:
79  int min_best_width = m_grid->GetTextExtent( wxT( "555,555555 mils" ) ).x;
80 
81  for( int i = 0; i < m_grid->GetNumberCols(); ++i )
82  {
83  // We calculate the column min size only from texts sizes, not using the initial col width
84  // as this initial width is sometimes strange depending on the language (wxGrid bug?)
85  int min_width = m_grid->GetVisibleWidth( i, true, true, false );
86 
87  m_grid->SetColMinimalWidth( i, min_width );
88 
89  // We use a "best size" >= min_best_width
90  m_grid->SetColSize( i, std::max( min_width, min_best_width ) );
91  }
92 
93  m_grid->PushEventHandler( new GRID_TRICKS( m_grid ) );
94 
95  m_Frame->Bind( UNITS_CHANGED, &PANEL_SETUP_TEXT_AND_GRAPHICS::onUnitsChanged, this );
96 }
Add mouse and command handling (such as cut, copy, and paste) to a WX_GRID instance.
Definition: grid_tricks.h:55
PANEL_SETUP_TEXT_AND_GRAPHICS_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)
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:590
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
wxTreebook * GetTreebook()
Definition: paged_dialog.h:37
BOARD * GetBoard() const
void onUnitsChanged(wxCommandEvent &aEvent)

References PCB_BASE_FRAME::GetBoard(), BOARD::GetDesignSettings(), WX_GRID::GetVisibleWidth(), m_BrdSettings, m_Frame, PANEL_SETUP_TEXT_AND_GRAPHICS_BASE::m_grid, m_Parent, and onUnitsChanged().

◆ ~PANEL_SETUP_TEXT_AND_GRAPHICS()

PANEL_SETUP_TEXT_AND_GRAPHICS::~PANEL_SETUP_TEXT_AND_GRAPHICS ( )
override

Definition at line 99 of file panel_setup_text_and_graphics.cpp.

100 {
101  // destroy GRID_TRICKS before m_grid.
102  m_grid->PopEventHandler( true );
103 
104  m_Frame->Unbind( UNITS_CHANGED, &PANEL_SETUP_TEXT_AND_GRAPHICS::onUnitsChanged, this );
105 }
void onUnitsChanged(wxCommandEvent &aEvent)

References m_Frame, PANEL_SETUP_TEXT_AND_GRAPHICS_BASE::m_grid, and onUnitsChanged().

Member Function Documentation

◆ getGridValue()

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

Definition at line 199 of file panel_setup_text_and_graphics.cpp.

200 {
201  return ValueFromString( m_Frame->GetUserUnits(), m_grid->GetCellValue( aRow, aCol ) );
202 }
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
EDA_UNITS GetUserUnits() const
Return the user units currently in use.

References EDA_BASE_FRAME::GetUserUnits(), m_Frame, PANEL_SETUP_TEXT_AND_GRAPHICS_BASE::m_grid, and ValueFromString().

Referenced by TransferDataFromWindow().

◆ ImportSettingsFrom()

void PANEL_SETUP_TEXT_AND_GRAPHICS::ImportSettingsFrom ( BOARD aBoard)

Definition at line 244 of file panel_setup_text_and_graphics.cpp.

245 {
246  if( !m_grid->CommitPendingChanges() )
247  return;
248 
249  BOARD_DESIGN_SETTINGS* savedSettings = m_BrdSettings;
250 
251  m_BrdSettings = &aBoard->GetDesignSettings();
253 
254  m_BrdSettings = savedSettings;
255 }
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:590
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:226
Container for design settings for a BOARD object.

References WX_GRID::CommitPendingChanges(), BOARD::GetDesignSettings(), m_BrdSettings, PANEL_SETUP_TEXT_AND_GRAPHICS_BASE::m_grid, and TransferDataToWindow().

Referenced by DIALOG_BOARD_SETUP::OnAuxiliaryAction().

◆ onUnitsChanged()

void PANEL_SETUP_TEXT_AND_GRAPHICS::onUnitsChanged ( wxCommandEvent &  aEvent)
private

Definition at line 108 of file panel_setup_text_and_graphics.cpp.

109 {
110  BOARD_DESIGN_SETTINGS tempBDS( nullptr, "dummy" );
112 
113  m_BrdSettings = &tempBDS; // No, address of stack var does not escape function
114 
117 
118  m_BrdSettings = saveBDS;
119 
120  aEvent.Skip();
121 }
Container for design settings for a BOARD object.

References m_BrdSettings, TransferDataFromWindow(), and TransferDataToWindow().

Referenced by PANEL_SETUP_TEXT_AND_GRAPHICS(), and ~PANEL_SETUP_TEXT_AND_GRAPHICS().

◆ TransferDataFromWindow()

bool PANEL_SETUP_TEXT_AND_GRAPHICS::TransferDataFromWindow ( )
override

Definition at line 205 of file panel_setup_text_and_graphics.cpp.

206 {
207  if( !m_grid->CommitPendingChanges() )
208  return false;
209 
210  for( int i = 0; i < ROW_COUNT; ++i )
211  {
213 
214  if( i == ROW_EDGES || i == ROW_COURTYARD )
215  continue;
216 
217  m_BrdSettings->m_TextSize[ i ] = wxSize( getGridValue( i, COL_TEXT_WIDTH ),
221  wxGridCellBoolEditor::IsTrueValue( m_grid->GetCellValue( i, COL_TEXT_ITALIC ) );
223  wxGridCellBoolEditor::IsTrueValue( m_grid->GetCellValue( i, COL_TEXT_UPRIGHT ) );
224  }
225 
226  // These are all stored in project file, not board, so no need for OnModify()
227 
228  int mode = m_dimensionUnits->GetSelection();
229  m_BrdSettings->m_DimensionUnitsMode = static_cast<DIM_UNITS_MODE>( mode );
230  int format = m_dimensionUnitsFormat->GetSelection();
231  m_BrdSettings->m_DimensionUnitsFormat = static_cast<DIM_UNITS_FORMAT>( format );
234  int position = m_dimensionTextPositionMode->GetSelection();
235  m_BrdSettings->m_DimensionTextPosition = static_cast<DIM_TEXT_POSITION>( position );
239 
240  return true;
241 }
int m_DimensionPrecision
Number of digits after the decimal.
DIM_TEXT_POSITION m_DimensionTextPosition
DIM_UNITS_MODE m_DimensionUnitsMode
wxSize m_TextSize[LAYER_CLASS_COUNT]
int m_TextThickness[LAYER_CLASS_COUNT]
bool m_TextItalic[LAYER_CLASS_COUNT]
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:226
int m_LineThickness[LAYER_CLASS_COUNT]
virtual long long int GetValue()
Return the current value in Internal Units.
DIM_UNITS_FORMAT m_DimensionUnitsFormat
bool m_TextUpright[LAYER_CLASS_COUNT]

References COL_LINE_THICKNESS, COL_TEXT_HEIGHT, COL_TEXT_ITALIC, COL_TEXT_THICKNESS, COL_TEXT_UPRIGHT, COL_TEXT_WIDTH, WX_GRID::CommitPendingChanges(), getGridValue(), UNIT_BINDER::GetValue(), m_arrowLength, m_BrdSettings, BOARD_DESIGN_SETTINGS::m_DimensionArrowLength, BOARD_DESIGN_SETTINGS::m_DimensionExtensionOffset, BOARD_DESIGN_SETTINGS::m_DimensionKeepTextAligned, PANEL_SETUP_TEXT_AND_GRAPHICS_BASE::m_dimensionPrecision, BOARD_DESIGN_SETTINGS::m_DimensionPrecision, PANEL_SETUP_TEXT_AND_GRAPHICS_BASE::m_dimensionSuppressZeroes, BOARD_DESIGN_SETTINGS::m_DimensionSuppressZeroes, PANEL_SETUP_TEXT_AND_GRAPHICS_BASE::m_dimensionTextKeepAligned, BOARD_DESIGN_SETTINGS::m_DimensionTextPosition, PANEL_SETUP_TEXT_AND_GRAPHICS_BASE::m_dimensionTextPositionMode, PANEL_SETUP_TEXT_AND_GRAPHICS_BASE::m_dimensionUnits, PANEL_SETUP_TEXT_AND_GRAPHICS_BASE::m_dimensionUnitsFormat, BOARD_DESIGN_SETTINGS::m_DimensionUnitsFormat, BOARD_DESIGN_SETTINGS::m_DimensionUnitsMode, m_extensionOffset, PANEL_SETUP_TEXT_AND_GRAPHICS_BASE::m_grid, BOARD_DESIGN_SETTINGS::m_LineThickness, BOARD_DESIGN_SETTINGS::m_TextItalic, BOARD_DESIGN_SETTINGS::m_TextSize, BOARD_DESIGN_SETTINGS::m_TextThickness, BOARD_DESIGN_SETTINGS::m_TextUpright, ROW_COUNT, ROW_COURTYARD, and ROW_EDGES.

Referenced by onUnitsChanged().

◆ TransferDataToWindow()

bool PANEL_SETUP_TEXT_AND_GRAPHICS::TransferDataToWindow ( )
override

Definition at line 124 of file panel_setup_text_and_graphics.cpp.

125 {
126  wxColour disabledColour = wxSystemSettings::GetColour( wxSYS_COLOUR_BACKGROUND );
127 
128 #define SET_MILS_CELL( row, col, val ) \
129  m_grid->SetCellValue( row, col, StringFromValue( m_Frame->GetUserUnits(), val, true ) )
130 
131 #define DISABLE_CELL( row, col ) \
132  m_grid->SetReadOnly( row, col ); m_grid->SetCellBackgroundColour( row, col, disabledColour );
133 
134  for( int i = 0; i < ROW_COUNT; ++i )
135  {
137 
138  if( i == ROW_EDGES || i == ROW_COURTYARD )
139  {
145  }
146  else
147  {
151  m_grid->SetCellValue( i, COL_TEXT_ITALIC, m_BrdSettings->m_TextItalic[ i ] ? wxT( "1" ) : wxEmptyString );
152  m_grid->SetCellValue( i, COL_TEXT_UPRIGHT, m_BrdSettings->m_TextUpright[ i ] ? wxT( "1" ) : wxEmptyString );
153 
154  auto attr = new wxGridCellAttr;
155  attr->SetRenderer( new wxGridCellBoolRenderer() );
156  attr->SetReadOnly(); // not really; we delegate interactivity to GRID_TRICKS
157  attr->SetAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
158  m_grid->SetAttr( i, COL_TEXT_ITALIC, attr );
159 
160  attr = new wxGridCellAttr;
161  attr->SetRenderer( new wxGridCellBoolRenderer() );
162  attr->SetReadOnly(); // not really; we delegate interactivity to GRID_TRICKS
163  attr->SetAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
164  m_grid->SetAttr( i, COL_TEXT_UPRIGHT, attr );
165  }
166  }
167 
168  // Work around an issue where wxWidgets doesn't calculate the row width on its own
169  for( int col = 0; col < m_grid->GetNumberCols(); col++ )
170  m_grid->SetColMinimalWidth( col, m_grid->GetVisibleWidth( col, true, true, false ) );
171 
172  m_grid->SetRowLabelSize( m_grid->GetVisibleWidth( -1, true, true, true ) );
173 
174  Layout();
175 
176  wxASSERT_MSG( m_BrdSettings->m_DimensionPrecision <= 4,
177  wxT( "Unhandled dimension precision!" ) );
178 
179  int mode = static_cast<int>( m_BrdSettings->m_DimensionUnitsMode );
180  m_dimensionUnits->SetSelection( mode );
181 
182  int format = static_cast<int>( m_BrdSettings->m_DimensionUnitsFormat );
183  m_dimensionUnitsFormat->SetSelection( format );
184 
187 
188  int position = static_cast<int>( m_BrdSettings->m_DimensionTextPosition );
189  m_dimensionTextPositionMode->SetSelection( position );
190 
194 
195  return true;
196 }
int m_DimensionPrecision
Number of digits after the decimal.
DIM_TEXT_POSITION m_DimensionTextPosition
DIM_UNITS_MODE m_DimensionUnitsMode
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]
#define DISABLE_CELL(row, col)
bool m_TextItalic[LAYER_CLASS_COUNT]
int m_LineThickness[LAYER_CLASS_COUNT]
virtual void SetValue(int aValue)
Set new value (in Internal Units) for the text field, taking care of units conversion.
DIM_UNITS_FORMAT m_DimensionUnitsFormat
#define SET_MILS_CELL(row, col, val)
bool m_TextUpright[LAYER_CLASS_COUNT]

References COL_LINE_THICKNESS, COL_TEXT_HEIGHT, COL_TEXT_ITALIC, COL_TEXT_THICKNESS, COL_TEXT_UPRIGHT, COL_TEXT_WIDTH, DISABLE_CELL, WX_GRID::GetVisibleWidth(), m_arrowLength, m_BrdSettings, BOARD_DESIGN_SETTINGS::m_DimensionArrowLength, BOARD_DESIGN_SETTINGS::m_DimensionExtensionOffset, BOARD_DESIGN_SETTINGS::m_DimensionKeepTextAligned, PANEL_SETUP_TEXT_AND_GRAPHICS_BASE::m_dimensionPrecision, BOARD_DESIGN_SETTINGS::m_DimensionPrecision, PANEL_SETUP_TEXT_AND_GRAPHICS_BASE::m_dimensionSuppressZeroes, BOARD_DESIGN_SETTINGS::m_DimensionSuppressZeroes, PANEL_SETUP_TEXT_AND_GRAPHICS_BASE::m_dimensionTextKeepAligned, BOARD_DESIGN_SETTINGS::m_DimensionTextPosition, PANEL_SETUP_TEXT_AND_GRAPHICS_BASE::m_dimensionTextPositionMode, PANEL_SETUP_TEXT_AND_GRAPHICS_BASE::m_dimensionUnits, PANEL_SETUP_TEXT_AND_GRAPHICS_BASE::m_dimensionUnitsFormat, BOARD_DESIGN_SETTINGS::m_DimensionUnitsFormat, BOARD_DESIGN_SETTINGS::m_DimensionUnitsMode, m_extensionOffset, PANEL_SETUP_TEXT_AND_GRAPHICS_BASE::m_grid, BOARD_DESIGN_SETTINGS::m_LineThickness, BOARD_DESIGN_SETTINGS::m_TextItalic, BOARD_DESIGN_SETTINGS::m_TextSize, BOARD_DESIGN_SETTINGS::m_TextThickness, BOARD_DESIGN_SETTINGS::m_TextUpright, ROW_COUNT, ROW_COURTYARD, ROW_EDGES, SET_MILS_CELL, and UNIT_BINDER::SetValue().

Referenced by ImportSettingsFrom(), and onUnitsChanged().

Member Data Documentation

◆ m_arrowLength

UNIT_BINDER PANEL_SETUP_TEXT_AND_GRAPHICS::m_arrowLength
private

Definition at line 58 of file panel_setup_text_and_graphics.h.

Referenced by TransferDataFromWindow(), and TransferDataToWindow().

◆ m_arrowLengthUnits

wxStaticText* PANEL_SETUP_TEXT_AND_GRAPHICS_BASE::m_arrowLengthUnits
protectedinherited

◆ m_BrdSettings

BOARD_DESIGN_SETTINGS* PANEL_SETUP_TEXT_AND_GRAPHICS::m_BrdSettings
private

◆ m_dimensionArrowLength

wxTextCtrl* PANEL_SETUP_TEXT_AND_GRAPHICS_BASE::m_dimensionArrowLength
protectedinherited

◆ m_dimensionExtensionOffset

wxTextCtrl* PANEL_SETUP_TEXT_AND_GRAPHICS_BASE::m_dimensionExtensionOffset
protectedinherited

◆ m_dimensionExtensionOffsetUnits

wxStaticText* PANEL_SETUP_TEXT_AND_GRAPHICS_BASE::m_dimensionExtensionOffsetUnits
protectedinherited

◆ m_dimensionPrecision

wxChoice* PANEL_SETUP_TEXT_AND_GRAPHICS_BASE::m_dimensionPrecision
protectedinherited

◆ m_dimensionSuppressZeroes

wxCheckBox* PANEL_SETUP_TEXT_AND_GRAPHICS_BASE::m_dimensionSuppressZeroes
protectedinherited

◆ m_dimensionTextKeepAligned

wxCheckBox* PANEL_SETUP_TEXT_AND_GRAPHICS_BASE::m_dimensionTextKeepAligned
protectedinherited

◆ m_dimensionTextPositionMode

wxChoice* PANEL_SETUP_TEXT_AND_GRAPHICS_BASE::m_dimensionTextPositionMode
protectedinherited

◆ m_dimensionUnits

wxChoice* PANEL_SETUP_TEXT_AND_GRAPHICS_BASE::m_dimensionUnits
protectedinherited

◆ m_dimensionUnitsFormat

wxChoice* PANEL_SETUP_TEXT_AND_GRAPHICS_BASE::m_dimensionUnitsFormat
protectedinherited

◆ m_extensionOffset

UNIT_BINDER PANEL_SETUP_TEXT_AND_GRAPHICS::m_extensionOffset
private

Definition at line 59 of file panel_setup_text_and_graphics.h.

Referenced by TransferDataFromWindow(), and TransferDataToWindow().

◆ m_Frame

PCB_EDIT_FRAME* PANEL_SETUP_TEXT_AND_GRAPHICS::m_Frame
private

◆ m_grid

◆ m_gridSizer

wxBoxSizer* PANEL_SETUP_TEXT_AND_GRAPHICS_BASE::m_gridSizer
protectedinherited

◆ m_lblArrowLength

wxStaticText* PANEL_SETUP_TEXT_AND_GRAPHICS_BASE::m_lblArrowLength
protectedinherited

◆ m_lblDimensionPrecision

wxStaticText* PANEL_SETUP_TEXT_AND_GRAPHICS_BASE::m_lblDimensionPrecision
protectedinherited

◆ m_lblDimensionUnits

wxStaticText* PANEL_SETUP_TEXT_AND_GRAPHICS_BASE::m_lblDimensionUnits
protectedinherited

◆ m_lblDimensionUnitsFormat

wxStaticText* PANEL_SETUP_TEXT_AND_GRAPHICS_BASE::m_lblDimensionUnitsFormat
protectedinherited

◆ m_lblExtensionOffset

wxStaticText* PANEL_SETUP_TEXT_AND_GRAPHICS_BASE::m_lblExtensionOffset
protectedinherited

◆ m_lblTextPositionMode

wxStaticText* PANEL_SETUP_TEXT_AND_GRAPHICS_BASE::m_lblTextPositionMode
protectedinherited

◆ m_panel1

wxPanel* PANEL_SETUP_TEXT_AND_GRAPHICS_BASE::m_panel1
protectedinherited

◆ m_Parent

PAGED_DIALOG* PANEL_SETUP_TEXT_AND_GRAPHICS::m_Parent
private

Definition at line 55 of file panel_setup_text_and_graphics.h.

Referenced by PANEL_SETUP_TEXT_AND_GRAPHICS().

◆ m_staticTextDefProp

wxStaticText* PANEL_SETUP_TEXT_AND_GRAPHICS_BASE::m_staticTextDefProp
protectedinherited

◆ m_staticTextDefPropDim

wxStaticText* PANEL_SETUP_TEXT_AND_GRAPHICS_BASE::m_staticTextDefPropDim
protectedinherited

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