KiCad PCB EDA Suite
UNIT_BINDER Class Reference

#include <unit_binder.h>

Inheritance diagram for UNIT_BINDER:

Public Member Functions

 UNIT_BINDER (EDA_DRAW_FRAME *aParent, wxStaticText *aLabel, wxWindow *aValue, wxStaticText *aUnitLabel, bool aUseMils=false, bool aAllowEval=true)
 Constructor. More...
 
virtual void SetUnits (EDA_UNITS_T aUnits, bool aUseMils=false)
 Function SetUnits Normally not needed (as the UNIT_BINDER inherits from the parent frame), but can be used to set to DEGREES for angular controls. More...
 
virtual void SetValue (int aValue)
 Function SetValue Sets new value (in Internal Units) for the text field, taking care of units conversion. More...
 
void SetValue (wxString aValue)
 
virtual void ChangeValue (int aValue)
 Function ChangeValue Changes the value (in Internal Units) for the text field, taking care of units conversion but does not trigger the update routine. More...
 
void ChangeValue (wxString aValue)
 
virtual int GetValue ()
 Function GetValue Returns the current value in Internal Units. More...
 
bool IsIndeterminate () const
 Function IsIndeterminate Returns true if the control holds the indeterminate value (for instance, if it represents a multiple selection of differing values). More...
 
virtual bool Validate (int aMin, int aMax, bool setFocusOnError=true)
 Function Validate Validates the control against the given range, informing the user of any errors found. More...
 
void SetLabel (const wxString &aLabel)
 
void Enable (bool aEnable)
 Function Enable Enables/diasables the label, widget and units label. More...
 
void Show (bool aShow, bool aResize=false)
 Function Show Shows/hides the label, widget and units label. More...
 

Protected Member Functions

void onSetFocus (wxFocusEvent &aEvent)
 
void onKillFocus (wxFocusEvent &aEvent)
 
void delayedFocusHandler (wxCommandEvent &aEvent)
 

Protected Attributes

wxStaticText * m_label
 

The bound widgets

More...
 
wxWindow * m_value
 
wxStaticText * m_unitLabel
 
EDA_UNITS_T m_units
 

Currently used units.

More...
 
bool m_useMils
 
wxString m_errorMessage
 

Validation support.

More...
 
NUMERIC_EVALUATOR m_eval
 

Evaluator

More...
 
bool m_allowEval
 
bool m_needsEval
 

Detailed Description

Definition at line 39 of file unit_binder.h.

Constructor & Destructor Documentation

◆ UNIT_BINDER()

UNIT_BINDER::UNIT_BINDER ( EDA_DRAW_FRAME aParent,
wxStaticText *  aLabel,
wxWindow *  aValue,
wxStaticText *  aUnitLabel,
bool  aUseMils = false,
bool  aAllowEval = true 
)

Constructor.

Parameters
aParentis the parent EDA_DRAW_FRAME.
aLabelis the static text used to label the text input widget (note: the label text, trimmed of its colon, will also be used in error messages)
aValueis the control used to edit or display the given value (wxTextCtrl, wxComboBox, wxStaticText, etc.).
aUnitLabelis the units label displayed after the text input widget
aUseMilsspecifies the use of mils for imperial units (instead of inches)
aAllowEvalindicates aTextInput's content should be eval'ed before storing

Definition at line 36 of file unit_binder.cpp.

38  :
39  m_label( aLabel ),
40  m_value( aValue ),
41  m_unitLabel( aUnitLabel ),
42  m_eval( aParent->GetUserUnits(), aUseMils )
43 {
44  // Fix the units (to the current units) for the life of the binder
45  m_units = aParent->GetUserUnits();
46  m_useMils = aUseMils;
47  m_allowEval = allowEval && dynamic_cast<wxTextEntry*>( m_value );
48  m_needsEval = false;
49 
50  auto textEntry = dynamic_cast<wxTextEntry*>( m_value );
51  if( textEntry )
52  {
53  // Use ChangeValue() instead of SetValue() so we don't generate events.
54  textEntry->ChangeValue( wxT( "0" ) );
55  }
56 
58 
59  m_value->Connect( wxEVT_SET_FOCUS, wxFocusEventHandler( UNIT_BINDER::onSetFocus ), NULL, this );
60  m_value->Connect( wxEVT_KILL_FOCUS, wxFocusEventHandler( UNIT_BINDER::onKillFocus ), NULL, this );
61  Connect( DELAY_FOCUS, wxCommandEventHandler( UNIT_BINDER::delayedFocusHandler ), NULL, this );
62 }
void delayedFocusHandler(wxCommandEvent &aEvent)
wxWindow * m_value
Definition: unit_binder.h:132
bool m_needsEval
Definition: unit_binder.h:145
EDA_UNITS_T GetUserUnits() const override
Return the user units currently in use.
Definition: draw_frame.h:289
wxStaticText * m_label
The bound widgets
Definition: unit_binder.h:131
wxStaticText * m_unitLabel
Definition: unit_binder.h:133
NUMERIC_EVALUATOR m_eval
Evaluator
Definition: unit_binder.h:143
bool m_useMils
Definition: unit_binder.h:137
bool m_allowEval
Definition: unit_binder.h:144
void onKillFocus(wxFocusEvent &aEvent)
Definition: unit_binder.cpp:91
void onSetFocus(wxFocusEvent &aEvent)
Definition: unit_binder.cpp:73
EDA_UNITS_T m_units
Currently used units.
Definition: unit_binder.h:136
wxString GetAbbreviatedUnitsLabel(EDA_UNITS_T aUnit, bool aUseMils)
Get the units string for a given units type.
Definition: base_units.cpp:432

References delayedFocusHandler(), GetAbbreviatedUnitsLabel(), EDA_DRAW_FRAME::GetUserUnits(), m_allowEval, m_needsEval, m_unitLabel, m_units, m_useMils, m_value, onKillFocus(), and onSetFocus().

Member Function Documentation

◆ ChangeValue() [1/2]

void UNIT_BINDER::ChangeValue ( int  aValue)
virtual

Function ChangeValue Changes the value (in Internal Units) for the text field, taking care of units conversion but does not trigger the update routine.

Parameters
aValueis the new value.

Definition at line 192 of file unit_binder.cpp.

193 {
194  ChangeValue( StringFromValue( m_units, aValue, false, m_useMils ) );
195 }
bool m_useMils
Definition: unit_binder.h:137
EDA_UNITS_T m_units
Currently used units.
Definition: unit_binder.h:136
wxString StringFromValue(EDA_UNITS_T aUnits, int aValue, bool aAddUnitSymbol, bool aUseMils)
Function StringFromValue returns the string from aValue according to units (inch, mm ....
Definition: base_units.cpp:210
virtual void ChangeValue(int aValue)
Function ChangeValue Changes the value (in Internal Units) for the text field, taking care of units c...

References m_units, m_useMils, and StringFromValue().

Referenced by DIALOG_PAD_PROPERTIES::onCornerSizePercentChange(), and DIALOG_TRACK_VIA_PROPERTIES::onViaSelect().

◆ ChangeValue() [2/2]

void UNIT_BINDER::ChangeValue ( wxString  aValue)

Definition at line 198 of file unit_binder.cpp.

199 {
200  auto textEntry = dynamic_cast<wxTextEntry*>( m_value );
201  auto staticText = dynamic_cast<wxStaticText*>( m_value );
202 
203  if( textEntry )
204  textEntry->ChangeValue( aValue );
205  else if( staticText )
206  staticText->SetLabel( aValue );
207 
208  if( m_allowEval )
209  m_eval.Clear();
210 
212 }
wxWindow * m_value
Definition: unit_binder.h:132
wxStaticText * m_unitLabel
Definition: unit_binder.h:133
NUMERIC_EVALUATOR m_eval
Evaluator
Definition: unit_binder.h:143
bool m_useMils
Definition: unit_binder.h:137
bool m_allowEval
Definition: unit_binder.h:144
EDA_UNITS_T m_units
Currently used units.
Definition: unit_binder.h:136
wxString GetAbbreviatedUnitsLabel(EDA_UNITS_T aUnit, bool aUseMils)
Get the units string for a given units type.
Definition: base_units.cpp:432

References NUMERIC_EVALUATOR::Clear(), GetAbbreviatedUnitsLabel(), m_allowEval, m_eval, m_unitLabel, m_units, m_useMils, and m_value.

◆ delayedFocusHandler()

void UNIT_BINDER::delayedFocusHandler ( wxCommandEvent &  aEvent)
protected

Definition at line 116 of file unit_binder.cpp.

117 {
118  if( !m_errorMessage.IsEmpty() )
119  DisplayError( m_value->GetParent(), m_errorMessage );
120 
121  m_errorMessage = wxEmptyString;
122  m_value->SetFocus();
123 }
wxString m_errorMessage
Validation support.
Definition: unit_binder.h:140
wxWindow * m_value
Definition: unit_binder.h:132
void DisplayError(wxWindow *parent, const wxString &text, int displaytime)
Function DisplayError displays an error or warning message box with aMessage.
Definition: confirm.cpp:244

References DisplayError(), m_errorMessage, and m_value.

Referenced by UNIT_BINDER().

◆ Enable()

void UNIT_BINDER::Enable ( bool  aEnable)

◆ GetValue()

int UNIT_BINDER::GetValue ( )
virtual

Function GetValue Returns the current value in Internal Units.

Definition at line 215 of file unit_binder.cpp.

216 {
217  auto textEntry = dynamic_cast<wxTextEntry*>( m_value );
218  auto staticText = dynamic_cast<wxStaticText*>( m_value );
219  wxString value;
220 
221  if( textEntry )
222  {
223  if( m_needsEval && m_eval.Process( textEntry->GetValue() ) )
224  value = m_eval.Result();
225  else
226  value = textEntry->GetValue();
227  }
228  else if( staticText )
229  value = staticText->GetLabel();
230  else
231  return 0;
232 
233  return ValueFromString( m_units, value, m_useMils );
234 }
wxWindow * m_value
Definition: unit_binder.h:132
bool m_needsEval
Definition: unit_binder.h:145
int ValueFromString(EDA_UNITS_T aUnits, const wxString &aTextValue, bool aUseMils)
Function ValueFromString converts aTextValue in aUnits to internal units used by the application.
Definition: base_units.cpp:409
bool Process(const wxString &aString)
NUMERIC_EVALUATOR m_eval
Evaluator
Definition: unit_binder.h:143
bool m_useMils
Definition: unit_binder.h:137
wxString Result() const
EDA_UNITS_T m_units
Currently used units.
Definition: unit_binder.h:136

References m_eval, m_needsEval, m_units, m_useMils, m_value, NUMERIC_EVALUATOR::Process(), NUMERIC_EVALUATOR::Result(), and ValueFromString().

Referenced by DIALOG_COPPER_ZONE::AcceptOptions(), DIALOG_PLOT::applyPlotSettings(), DIALOG_CREATE_ARRAY::calculateCircularArrayProperties(), DIALOG_TRACK_VIA_PROPERTIES::DIALOG_TRACK_VIA_PROPERTIES(), DIALOG_EXPORT_SVG::ExportSVGFile(), DIALOG_PAGES_SETTINGS::GetCustomSizeMilsFromDialog(), DIALOG_SCH_SHEET_PROPS::GetFileNameTextSize(), DIALOG_PLOT_SCHEMATIC::getPlotOptions(), DIALOG_SCH_SHEET_PROPS::GetSheetNameTextSize(), DIALOG_POSITION_RELATIVE::GetTranslationInIU(), DIALOG_MOVE_EXACT::GetTranslationInIU(), DIALOG_LIB_EDIT_DRAW_ITEM::GetWidth(), DIALOG_PAD_PRIMITIVE_POLY_PROPS::onCellChanging(), DIALOG_PAD_PROPERTIES::onCornerRadiusChange(), DIALOG_POSITION_RELATIVE::OnOkClick(), DIALOG_LIB_EDIT_PIN::OnPropertiesChange(), DIALOG_PAD_PROPERTIES::PadTypeSelected(), DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS::processItem(), DIALOG_DRC_CONTROL::SetDrcParmeters(), DIALOG_PLOT_SCHEMATIC::SetHPGLPenWidth(), DIALOG_TRACK_VIA_SIZE::TransferDataFromWindow(), DIALOG_EDIT_LINE_STYLE::TransferDataFromWindow(), DIALOG_TRACK_VIA_PROPERTIES::TransferDataFromWindow(), DIALOG_PNS_DIFF_PAIR_DIMENSIONS::TransferDataFromWindow(), DIALOG_PNS_LENGTH_TUNING_SETTINGS::TransferDataFromWindow(), DIALOG_LIB_EDIT_TEXT::TransferDataFromWindow(), PANEL_SETUP_MASK_AND_PASTE::TransferDataFromWindow(), DIALOG_NON_COPPER_ZONES_EDITOR::TransferDataFromWindow(), DIALOG_SCH_EDIT_SHEET_PIN::TransferDataFromWindow(), DIALOG_LIB_EDIT_PIN::TransferDataFromWindow(), PANEL_SETUP_FEATURE_CONSTRAINTS::TransferDataFromWindow(), DIALOG_SET_GRID::TransferDataFromWindow(), DIALOG_EDIT_ONE_FIELD::TransferDataFromWindow(), DIALOG_TEXT_PROPERTIES::TransferDataFromWindow(), DIALOG_EDIT_COMPONENT_IN_LIBRARY::TransferDataFromWindow(), DIALOG_GRAPHIC_ITEM_PROPERTIES::TransferDataFromWindow(), DIALOG_COPPER_ZONE::TransferDataFromWindow(), DIALOG_FOOTPRINT_FP_EDITOR::TransferDataFromWindow(), DIALOG_MOVE_EXACT::TransferDataFromWindow(), DIALOG_TARGET_PROPERTIES::TransferDataFromWindow(), DIALOG_LABEL_EDITOR::TransferDataFromWindow(), DIALOG_CREATE_ARRAY::TransferDataFromWindow(), PANEL_SETUP_LAYERS::TransferDataFromWindow(), DIALOG_FOOTPRINT_BOARD_EDITOR::TransferDataFromWindow(), DIALOG_PAD_PRIMITIVES_PROPERTIES::TransferDataFromWindow(), DIALOG_PAD_PRIMITIVE_POLY_PROPS::TransferDataFromWindow(), DIALOG_PAD_PROPERTIES::transferDataToPad(), DIALOG_PAD_PRIMITIVES_TRANSFORM::Transform(), DIALOG_GRAPHIC_ITEM_PROPERTIES::Validate(), Validate(), PANEL_SETUP_TRACKS_AND_VIAS::validateData(), PANEL_SETUP_NETCLASSES::validateData(), and DIALOG_EXPORT_SVG::~DIALOG_EXPORT_SVG().

◆ IsIndeterminate()

bool UNIT_BINDER::IsIndeterminate ( ) const

Function IsIndeterminate Returns true if the control holds the indeterminate value (for instance, if it represents a multiple selection of differing values).

Definition at line 237 of file unit_binder.cpp.

238 {
239  auto textEntry = dynamic_cast<wxTextEntry*>( m_value );
240 
241  if( textEntry )
242  return textEntry->GetValue() == INDETERMINATE;
243 
244  return false;
245 }
wxWindow * m_value
Definition: unit_binder.h:132
#define INDETERMINATE

References INDETERMINATE, and m_value.

Referenced by DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS::processItem(), and DIALOG_TRACK_VIA_PROPERTIES::TransferDataFromWindow().

◆ onKillFocus()

void UNIT_BINDER::onKillFocus ( wxFocusEvent &  aEvent)
protected

Definition at line 91 of file unit_binder.cpp.

92 {
93  auto textEntry = dynamic_cast<wxTextEntry*>( m_value );
94 
95  if( m_allowEval && textEntry )
96  {
97  if( m_eval.Process( textEntry->GetValue() ) )
98  textEntry->ChangeValue( m_eval.Result() );
99 
100  m_needsEval = false;
101  }
102 
103  aEvent.Skip();
104 }
wxWindow * m_value
Definition: unit_binder.h:132
bool m_needsEval
Definition: unit_binder.h:145
bool Process(const wxString &aString)
NUMERIC_EVALUATOR m_eval
Evaluator
Definition: unit_binder.h:143
bool m_allowEval
Definition: unit_binder.h:144
wxString Result() const

References m_allowEval, m_eval, m_needsEval, m_value, NUMERIC_EVALUATOR::Process(), and NUMERIC_EVALUATOR::Result().

Referenced by UNIT_BINDER().

◆ onSetFocus()

void UNIT_BINDER::onSetFocus ( wxFocusEvent &  aEvent)
protected

Definition at line 73 of file unit_binder.cpp.

74 {
75  auto textEntry = dynamic_cast<wxTextEntry*>( m_value );
76 
77  if( m_allowEval && textEntry )
78  {
79  wxString oldStr = m_eval.OriginalText();
80 
81  if( oldStr.length() )
82  textEntry->SetValue( oldStr );
83 
84  m_needsEval = true;
85  }
86 
87  aEvent.Skip();
88 }
wxWindow * m_value
Definition: unit_binder.h:132
wxString OriginalText() const
bool m_needsEval
Definition: unit_binder.h:145
NUMERIC_EVALUATOR m_eval
Evaluator
Definition: unit_binder.h:143
bool m_allowEval
Definition: unit_binder.h:144

References m_allowEval, m_eval, m_needsEval, m_value, and NUMERIC_EVALUATOR::OriginalText().

Referenced by UNIT_BINDER().

◆ SetLabel()

void UNIT_BINDER::SetLabel ( const wxString &  aLabel)

Definition at line 248 of file unit_binder.cpp.

249 {
250  m_label->SetLabel( aLabel );
251 }
wxStaticText * m_label
The bound widgets
Definition: unit_binder.h:131

References m_label.

Referenced by DIALOG_POSITION_RELATIVE::updateDialogControls(), and DIALOG_MOVE_EXACT::updateDialogControls().

◆ SetUnits()

void UNIT_BINDER::SetUnits ( EDA_UNITS_T  aUnits,
bool  aUseMils = false 
)
virtual

Function SetUnits Normally not needed (as the UNIT_BINDER inherits from the parent frame), but can be used to set to DEGREES for angular controls.

Definition at line 65 of file unit_binder.cpp.

66 {
67  m_units = aUnits;
68  m_useMils = aUseMils;
70 }
wxStaticText * m_unitLabel
Definition: unit_binder.h:133
bool m_useMils
Definition: unit_binder.h:137
EDA_UNITS_T m_units
Currently used units.
Definition: unit_binder.h:136
wxString GetAbbreviatedUnitsLabel(EDA_UNITS_T aUnit, bool aUseMils)
Get the units string for a given units type.
Definition: base_units.cpp:432

References GetAbbreviatedUnitsLabel(), m_unitLabel, m_units, and m_useMils.

Referenced by DIALOG_CREATE_ARRAY::DIALOG_CREATE_ARRAY(), DIALOG_GRAPHIC_ITEM_PROPERTIES::DIALOG_GRAPHIC_ITEM_PROPERTIES(), DIALOG_MOVE_EXACT::DIALOG_MOVE_EXACT(), DIALOG_PAD_PRIMITIVES_TRANSFORM::DIALOG_PAD_PRIMITIVES_TRANSFORM(), DIALOG_NON_COPPER_ZONES_EDITOR::TransferDataToWindow(), DIALOG_COPPER_ZONE::TransferDataToWindow(), DIALOG_PAD_PRIMITIVES_PROPERTIES::TransferDataToWindow(), DIALOG_POSITION_RELATIVE::updateDialogControls(), and DIALOG_MOVE_EXACT::updateDialogControls().

◆ SetValue() [1/2]

void UNIT_BINDER::SetValue ( int  aValue)
virtual

Function SetValue Sets new value (in Internal Units) for the text field, taking care of units conversion.

Parameters
aValueis the new value.

Definition at line 169 of file unit_binder.cpp.

170 {
171  SetValue( StringFromValue( m_units, aValue, false, m_useMils ) );
172 }
bool m_useMils
Definition: unit_binder.h:137
virtual void SetValue(int aValue)
Function SetValue Sets new value (in Internal Units) for the text field, taking care of units convers...
EDA_UNITS_T m_units
Currently used units.
Definition: unit_binder.h:136
wxString StringFromValue(EDA_UNITS_T aUnits, int aValue, bool aAddUnitSymbol, bool aUseMils)
Function StringFromValue returns the string from aValue according to units (inch, mm ....
Definition: base_units.cpp:210

References m_units, m_useMils, and StringFromValue().

Referenced by DIALOG_PLOT::applyPlotSettings(), DIALOG_CREATE_ARRAY::calculateCircularArrayProperties(), DIALOG_MOVE_EXACT::DIALOG_MOVE_EXACT(), DIALOG_POSITION_RELATIVE::DIALOG_POSITION_RELATIVE(), DIALOG_TRACK_VIA_PROPERTIES::DIALOG_TRACK_VIA_PROPERTIES(), DIALOG_DRC_CONTROL::DisplayDRCValues(), DIALOG_PLOT::init_Dialog(), DIALOG_EXPORT_SVG::initDialog(), DIALOG_PAGES_SETTINGS::initDialog(), DIALOG_PLOT_SCHEMATIC::initDlg(), DIALOG_PAD_PROPERTIES::initValues(), DIALOG_POSITION_RELATIVE::OnClear(), DIALOG_MOVE_EXACT::OnClear(), DIALOG_POSITION_RELATIVE::OnPolarChanged(), DIALOG_MOVE_EXACT::OnPolarChanged(), DIALOG_SET_GRID::OnResetGridOrgClick(), DIALOG_PAD_PROPERTIES::PadTypeSelected(), DIALOG_EDIT_LINE_STYLE::resetDefaults(), DIALOG_EDIT_LINE_STYLE::TransferDataToWindow(), DIALOG_TRACK_VIA_SIZE::TransferDataToWindow(), DIALOG_LIB_EDIT_DRAW_ITEM::TransferDataToWindow(), DIALOG_PNS_DIFF_PAIR_DIMENSIONS::TransferDataToWindow(), DIALOG_PNS_LENGTH_TUNING_SETTINGS::TransferDataToWindow(), DIALOG_SCH_SHEET_PROPS::TransferDataToWindow(), DIALOG_LIB_EDIT_TEXT::TransferDataToWindow(), PANEL_SETUP_MASK_AND_PASTE::TransferDataToWindow(), DIALOG_NON_COPPER_ZONES_EDITOR::TransferDataToWindow(), DIALOG_SCH_EDIT_SHEET_PIN::TransferDataToWindow(), DIALOG_LIB_EDIT_PIN::TransferDataToWindow(), PANEL_SETUP_FEATURE_CONSTRAINTS::TransferDataToWindow(), DIALOG_EDIT_ONE_FIELD::TransferDataToWindow(), DIALOG_SET_GRID::TransferDataToWindow(), DIALOG_TEXT_PROPERTIES::TransferDataToWindow(), DIALOG_EDIT_COMPONENT_IN_LIBRARY::TransferDataToWindow(), DIALOG_GRAPHIC_ITEM_PROPERTIES::TransferDataToWindow(), DIALOG_COPPER_ZONE::TransferDataToWindow(), DIALOG_FOOTPRINT_FP_EDITOR::TransferDataToWindow(), DIALOG_TARGET_PROPERTIES::TransferDataToWindow(), DIALOG_LABEL_EDITOR::TransferDataToWindow(), PANEL_SETUP_LAYERS::TransferDataToWindow(), DIALOG_FOOTPRINT_BOARD_EDITOR::TransferDataToWindow(), DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS::TransferDataToWindow(), DIALOG_PAD_PRIMITIVES_PROPERTIES::TransferDataToWindow(), DIALOG_PAD_PRIMITIVE_POLY_PROPS::TransferDataToWindow(), and DIALOG_PAD_PROPERTIES::updateRoundRectCornerValues().

◆ SetValue() [2/2]

void UNIT_BINDER::SetValue ( wxString  aValue)

Definition at line 175 of file unit_binder.cpp.

176 {
177  auto textEntry = dynamic_cast<wxTextEntry*>( m_value );
178  auto staticText = dynamic_cast<wxStaticText*>( m_value );
179 
180  if( textEntry )
181  textEntry->SetValue( aValue );
182  else if( staticText )
183  staticText->SetLabel( aValue );
184 
185  if( m_allowEval )
186  m_eval.Clear();
187 
189 }
wxWindow * m_value
Definition: unit_binder.h:132
wxStaticText * m_unitLabel
Definition: unit_binder.h:133
NUMERIC_EVALUATOR m_eval
Evaluator
Definition: unit_binder.h:143
bool m_useMils
Definition: unit_binder.h:137
bool m_allowEval
Definition: unit_binder.h:144
EDA_UNITS_T m_units
Currently used units.
Definition: unit_binder.h:136
wxString GetAbbreviatedUnitsLabel(EDA_UNITS_T aUnit, bool aUseMils)
Get the units string for a given units type.
Definition: base_units.cpp:432

References NUMERIC_EVALUATOR::Clear(), GetAbbreviatedUnitsLabel(), m_allowEval, m_eval, m_unitLabel, m_units, m_useMils, and m_value.

◆ Show()

void UNIT_BINDER::Show ( bool  aShow,
bool  aResize = false 
)

Function Show Shows/hides the label, widget and units label.

Parameters
aShowcalled for the Show() routine in wx
aResizeif true, the element will be sized to 0 on hide and -1 on show

Definition at line 262 of file unit_binder.cpp.

263 {
264  m_label->Show( aShow );
265  m_value->Show( aShow );
266  m_unitLabel->Show( aShow );
267 
268  if( aResize )
269  {
270  if( aShow )
271  {
272  m_label->SetSize( -1, -1 );
273  m_value->SetSize( -1, -1 );
274  m_unitLabel->SetSize( -1, -1 );
275  }
276  else
277  {
278  m_label->SetSize( 0, 0 );
279  m_value->SetSize( 0, 0 );
280  m_unitLabel->SetSize( 0, 0 );
281  }
282  }
283 }
wxWindow * m_value
Definition: unit_binder.h:132
wxStaticText * m_label
The bound widgets
Definition: unit_binder.h:131
wxStaticText * m_unitLabel
Definition: unit_binder.h:133

References m_label, m_unitLabel, and m_value.

Referenced by DIALOG_GRAPHIC_ITEM_PROPERTIES::TransferDataToWindow(), and DIALOG_PAD_PRIMITIVES_PROPERTIES::TransferDataToWindow().

◆ Validate()

bool UNIT_BINDER::Validate ( int  aMin,
int  aMax,
bool  setFocusOnError = true 
)
virtual

Function Validate Validates the control against the given range, informing the user of any errors found.

Parameters
aMina minimum value (in internal units) for validation
aMaxa maximum value (in internal units) for validation
Returns
false on error.

Definition at line 126 of file unit_binder.cpp.

127 {
128  auto textEntry = dynamic_cast<wxTextEntry*>( m_value );
129 
130  if( !textEntry || textEntry->GetValue() == INDETERMINATE )
131  return true;
132 
133  if( GetValue() < aMin )
134  {
135  m_errorMessage = wxString::Format( _( "%s must be at least %s." ),
137  StringFromValue( m_units, aMin, true ) );
138 
139  if( setFocusOnError )
140  {
141  textEntry->SelectAll();
142  // Don't focus directly; we might be inside a KillFocus event handler
143  wxPostEvent( this, wxCommandEvent( DELAY_FOCUS ) );
144  }
145 
146  return false;
147  }
148 
149  if( GetValue() > aMax )
150  {
151  m_errorMessage = wxString::Format( _( "%s must be less than %s." ),
153  StringFromValue( m_units, aMax, true ) );
154 
155  if( setFocusOnError )
156  {
157  textEntry->SelectAll();
158  // Don't focus directly; we might be inside a KillFocus event handler
159  wxPostEvent( this, wxCommandEvent( DELAY_FOCUS ) );
160  }
161 
162  return false;
163  }
164 
165  return true;
166 }
wxString m_errorMessage
Validation support.
Definition: unit_binder.h:140
wxWindow * m_value
Definition: unit_binder.h:132
wxString valueDescriptionFromLabel(wxStaticText *aLabel)
virtual int GetValue()
Function GetValue Returns the current value in Internal Units.
#define INDETERMINATE
wxStaticText * m_label
The bound widgets
Definition: unit_binder.h:131
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
EDA_UNITS_T m_units
Currently used units.
Definition: unit_binder.h:136
wxString StringFromValue(EDA_UNITS_T aUnits, int aValue, bool aAddUnitSymbol, bool aUseMils)
Function StringFromValue returns the string from aValue according to units (inch, mm ....
Definition: base_units.cpp:210

References Format(), GetValue(), INDETERMINATE, m_errorMessage, m_label, m_units, m_value, StringFromValue(), and valueDescriptionFromLabel().

Referenced by DIALOG_COPPER_ZONE::AcceptOptions(), DIALOG_PAGES_SETTINGS::OnOkClick(), DIALOG_TRACK_VIA_PROPERTIES::TransferDataFromWindow(), DIALOG_NON_COPPER_ZONES_EDITOR::TransferDataFromWindow(), DIALOG_SET_GRID::TransferDataFromWindow(), DIALOG_TEXT_PROPERTIES::TransferDataFromWindow(), DIALOG_TARGET_PROPERTIES::TransferDataFromWindow(), DIALOG_LABEL_EDITOR::TransferDataFromWindow(), DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS::TransferDataFromWindow(), DIALOG_PAD_PROPERTIES::transferDataToPad(), DIALOG_FOOTPRINT_FP_EDITOR::Validate(), and DIALOG_FOOTPRINT_BOARD_EDITOR::Validate().

Member Data Documentation

◆ m_allowEval

bool UNIT_BINDER::m_allowEval
protected

Definition at line 144 of file unit_binder.h.

Referenced by ChangeValue(), onKillFocus(), onSetFocus(), SetValue(), and UNIT_BINDER().

◆ m_errorMessage

wxString UNIT_BINDER::m_errorMessage
protected

Validation support.

Definition at line 140 of file unit_binder.h.

Referenced by delayedFocusHandler(), and Validate().

◆ m_eval

NUMERIC_EVALUATOR UNIT_BINDER::m_eval
protected

Evaluator

Definition at line 143 of file unit_binder.h.

Referenced by ChangeValue(), GetValue(), onKillFocus(), onSetFocus(), and SetValue().

◆ m_label

wxStaticText* UNIT_BINDER::m_label
protected

The bound widgets

Definition at line 131 of file unit_binder.h.

Referenced by Enable(), SetLabel(), Show(), and Validate().

◆ m_needsEval

bool UNIT_BINDER::m_needsEval
protected

Definition at line 145 of file unit_binder.h.

Referenced by GetValue(), onKillFocus(), onSetFocus(), and UNIT_BINDER().

◆ m_unitLabel

wxStaticText* UNIT_BINDER::m_unitLabel
protected

Definition at line 133 of file unit_binder.h.

Referenced by ChangeValue(), Enable(), SetUnits(), SetValue(), Show(), and UNIT_BINDER().

◆ m_units

EDA_UNITS_T UNIT_BINDER::m_units
protected

Currently used units.

Definition at line 136 of file unit_binder.h.

Referenced by ChangeValue(), GetValue(), SetUnits(), SetValue(), UNIT_BINDER(), and Validate().

◆ m_useMils

bool UNIT_BINDER::m_useMils
protected

Definition at line 137 of file unit_binder.h.

Referenced by ChangeValue(), GetValue(), SetUnits(), SetValue(), and UNIT_BINDER().

◆ m_value

wxWindow* UNIT_BINDER::m_value
protected

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