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 long long 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 (long long int aMin, long long 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
 
long m_selStart
 

Selection start and end of the original text

More...
 
long m_selEnd
 

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 37 of file unit_binder.cpp.

39  :
40  m_label( aLabel ),
41  m_value( aValue ),
42  m_unitLabel( aUnitLabel ),
43  m_eval( aParent->GetUserUnits(), aUseMils )
44 {
45  // Fix the units (to the current units) for the life of the binder
46  m_units = aParent->GetUserUnits();
47  m_useMils = aUseMils;
48  m_allowEval = allowEval && dynamic_cast<wxTextEntry*>( m_value );
49  m_needsEval = false;
50  m_selStart = 0;
51  m_selEnd = 0;
52 
53  auto textEntry = dynamic_cast<wxTextEntry*>( m_value );
54  if( textEntry )
55  {
56  // Use ChangeValue() instead of SetValue() so we don't generate events.
57  textEntry->ChangeValue( wxT( "0" ) );
58  }
59 
61 
62  m_value->Connect( wxEVT_SET_FOCUS, wxFocusEventHandler( UNIT_BINDER::onSetFocus ), NULL, this );
63  m_value->Connect( wxEVT_KILL_FOCUS, wxFocusEventHandler( UNIT_BINDER::onKillFocus ), NULL, this );
64  Connect( DELAY_FOCUS, wxCommandEventHandler( UNIT_BINDER::delayedFocusHandler ), NULL, this );
65 }
void delayedFocusHandler(wxCommandEvent &aEvent)
wxWindow * m_value
Definition: unit_binder.h:132
bool m_needsEval
Definition: unit_binder.h:145
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:97
void onSetFocus(wxFocusEvent &aEvent)
Definition: unit_binder.cpp:76
EDA_UNITS_T GetUserUnits() const
Return the user units currently in use.
EDA_UNITS_T m_units
Currently used units.
Definition: unit_binder.h:136
long m_selStart
Selection start and end of the original text
Definition: unit_binder.h:148
wxString GetAbbreviatedUnitsLabel(EDA_UNITS_T aUnit, bool aUseMils)
Get the units string for a given units type.
Definition: base_units.cpp:450

References delayedFocusHandler(), GetAbbreviatedUnitsLabel(), EDA_BASE_FRAME::GetUserUnits(), m_allowEval, m_needsEval, m_selEnd, m_selStart, 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 215 of file unit_binder.cpp.

216 {
217  ChangeValue( StringFromValue( m_units, aValue, false, m_useMils ) );
218 }
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, double aValue, bool aAddUnitSymbol, bool aUseMils)
Function StringFromValue returns the string from aValue according to units (inch, mm ....
Definition: base_units.cpp:217
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 221 of file unit_binder.cpp.

222 {
223  auto textEntry = dynamic_cast<wxTextEntry*>( m_value );
224  auto staticText = dynamic_cast<wxStaticText*>( m_value );
225 
226  if( textEntry )
227  textEntry->ChangeValue( aValue );
228  else if( staticText )
229  staticText->SetLabel( aValue );
230 
231  if( m_allowEval )
232  m_eval.Clear();
233 
235 }
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:450

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 139 of file unit_binder.cpp.

140 {
141  if( !m_errorMessage.IsEmpty() )
142  DisplayError( m_value->GetParent(), m_errorMessage );
143 
144  m_errorMessage = wxEmptyString;
145  m_value->SetFocus();
146 }
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:236
wxString m_errorMessage
Validation support.
Definition: unit_binder.h:140
wxWindow * m_value
Definition: unit_binder.h:132

References DisplayError(), m_errorMessage, and m_value.

Referenced by UNIT_BINDER().

◆ Enable()

void UNIT_BINDER::Enable ( bool  aEnable)

◆ GetValue()

long long int UNIT_BINDER::GetValue ( )
virtual

Function GetValue Returns the current value in Internal Units.

Definition at line 238 of file unit_binder.cpp.

239 {
240  auto textEntry = dynamic_cast<wxTextEntry*>( m_value );
241  auto staticText = dynamic_cast<wxStaticText*>( m_value );
242  wxString value;
243 
244  if( textEntry )
245  {
246  if( m_needsEval && m_eval.Process( textEntry->GetValue() ) )
247  value = m_eval.Result();
248  else
249  value = textEntry->GetValue();
250  }
251  else if( staticText )
252  value = staticText->GetLabel();
253  else
254  return 0;
255 
256  return ValueFromString( m_units, value, m_useMils );
257 }
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_useMils
Definition: unit_binder.h:137
wxString Result() const
EDA_UNITS_T m_units
Currently used units.
Definition: unit_binder.h:136
long long 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:427

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

Referenced by DIALOG_PNS_LENGTH_TUNING_SETTINGS::AcceptOptions(), 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_MOVE_EXACT::OnTextChanged(), DIALOG_PAD_PROPERTIES::PadTypeSelected(), DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS::processItem(), DIALOG_DRC_CONTROL::SetDRCParameters(), DIALOG_PLOT_SCHEMATIC::SetHPGLPenWidth(), DIALOG_TRACK_VIA_PROPERTIES::TransferDataFromWindow(), DIALOG_TRACK_VIA_SIZE::TransferDataFromWindow(), DIALOG_EDIT_LINE_STYLE::TransferDataFromWindow(), DIALOG_PNS_DIFF_PAIR_DIMENSIONS::TransferDataFromWindow(), PANEL_EESCHEMA_DISPLAY_OPTIONS::TransferDataFromWindow(), DIALOG_PNS_LENGTH_TUNING_SETTINGS::TransferDataFromWindow(), DIALOG_SET_GRID::TransferDataFromWindow(), DIALOG_EDIT_SHEET_PIN::TransferDataFromWindow(), DIALOG_LIB_EDIT_TEXT::TransferDataFromWindow(), PANEL_SETUP_MASK_AND_PASTE::TransferDataFromWindow(), DIALOG_TARGET_PROPERTIES::TransferDataFromWindow(), DIALOG_NON_COPPER_ZONES_EDITOR::TransferDataFromWindow(), DIALOG_LIB_EDIT_PIN::TransferDataFromWindow(), DIALOG_EDIT_ONE_FIELD::TransferDataFromWindow(), PANEL_SETUP_FEATURE_CONSTRAINTS::TransferDataFromWindow(), DIALOG_CREATE_ARRAY::TransferDataFromWindow(), DIALOG_TEXT_PROPERTIES::TransferDataFromWindow(), DIALOG_GRAPHIC_ITEM_PROPERTIES::TransferDataFromWindow(), DIALOG_COPPER_ZONE::TransferDataFromWindow(), DIALOG_EDIT_COMPONENT_IN_LIBRARY::TransferDataFromWindow(), DIALOG_FOOTPRINT_FP_EDITOR::TransferDataFromWindow(), DIALOG_LABEL_EDITOR::TransferDataFromWindow(), DIALOG_MOVE_EXACT::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(), DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS::visitItem(), 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 260 of file unit_binder.cpp.

261 {
262  auto textEntry = dynamic_cast<wxTextEntry*>( m_value );
263 
264  if( textEntry )
265  return textEntry->GetValue() == INDETERMINATE;
266 
267  return false;
268 }
wxWindow * m_value
Definition: unit_binder.h:132
#define INDETERMINATE

References INDETERMINATE, and m_value.

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

◆ onKillFocus()

void UNIT_BINDER::onKillFocus ( wxFocusEvent &  aEvent)
protected

Definition at line 97 of file unit_binder.cpp.

98 {
99  auto textEntry = dynamic_cast<wxTextEntry*>( m_value );
100 
101  if( m_allowEval && textEntry )
102  {
103  if( m_eval.Process( textEntry->GetValue() ) )
104  {
105  textEntry->GetSelection( &m_selStart, &m_selEnd );
106  wxString sel = textEntry->GetStringSelection();
107 
108  textEntry->ChangeValue( m_eval.Result() );
109 
110 #ifdef __WXGTK__
111  // Manually copy the selected text to the primary selection clipboard
112  if( wxTheClipboard->Open() )
113  {
114  bool clipTarget = wxTheClipboard->IsUsingPrimarySelection();
115  wxTheClipboard->UsePrimarySelection( true );
116  wxTheClipboard->SetData( new wxTextDataObject( sel ) );
117  wxTheClipboard->UsePrimarySelection( clipTarget );
118  wxTheClipboard->Close();
119  }
120 #endif
121  }
122 
123  m_needsEval = false;
124  }
125 
126  aEvent.Skip();
127 }
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
long m_selStart
Selection start and end of the original text
Definition: unit_binder.h:148

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

Referenced by UNIT_BINDER().

◆ onSetFocus()

void UNIT_BINDER::onSetFocus ( wxFocusEvent &  aEvent)
protected

Definition at line 76 of file unit_binder.cpp.

77 {
78  auto textEntry = dynamic_cast<wxTextEntry*>( m_value );
79 
80  if( m_allowEval && textEntry )
81  {
82  wxString oldStr = m_eval.OriginalText();
83 
84  if( oldStr.length() )
85  {
86  textEntry->SetValue( oldStr );
87  textEntry->SetSelection( m_selStart, m_selEnd );
88  }
89 
90  m_needsEval = true;
91  }
92 
93  aEvent.Skip();
94 }
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
long m_selStart
Selection start and end of the original text
Definition: unit_binder.h:148

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

Referenced by UNIT_BINDER().

◆ SetLabel()

void UNIT_BINDER::SetLabel ( const wxString &  aLabel)

Definition at line 271 of file unit_binder.cpp.

272 {
273  m_label->SetLabel( aLabel );
274 }
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

◆ 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 192 of file unit_binder.cpp.

193 {
194  SetValue( StringFromValue( m_units, aValue, false, m_useMils ) );
195 }
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, double aValue, bool aAddUnitSymbol, bool aUseMils)
Function StringFromValue returns the string from aValue according to units (inch, mm ....
Definition: base_units.cpp:217

References m_units, m_useMils, and StringFromValue().

Referenced by DIALOG_COPPER_ZONE::AcceptOptions(), 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(), PANEL_EESCHEMA_DISPLAY_OPTIONS::TransferDataToWindow(), DIALOG_PNS_DIFF_PAIR_DIMENSIONS::TransferDataToWindow(), DIALOG_LIB_EDIT_DRAW_ITEM::TransferDataToWindow(), DIALOG_PNS_LENGTH_TUNING_SETTINGS::TransferDataToWindow(), DIALOG_EDIT_SHEET_PIN::TransferDataToWindow(), DIALOG_SCH_SHEET_PROPS::TransferDataToWindow(), DIALOG_SET_GRID::TransferDataToWindow(), DIALOG_LIB_EDIT_TEXT::TransferDataToWindow(), PANEL_SETUP_MASK_AND_PASTE::TransferDataToWindow(), DIALOG_TARGET_PROPERTIES::TransferDataToWindow(), DIALOG_NON_COPPER_ZONES_EDITOR::TransferDataToWindow(), DIALOG_LIB_EDIT_PIN::TransferDataToWindow(), DIALOG_EDIT_ONE_FIELD::TransferDataToWindow(), PANEL_SETUP_FEATURE_CONSTRAINTS::TransferDataToWindow(), DIALOG_TEXT_PROPERTIES::TransferDataToWindow(), DIALOG_GRAPHIC_ITEM_PROPERTIES::TransferDataToWindow(), DIALOG_COPPER_ZONE::TransferDataToWindow(), DIALOG_EDIT_COMPONENT_IN_LIBRARY::TransferDataToWindow(), DIALOG_FOOTPRINT_FP_EDITOR::TransferDataToWindow(), DIALOG_LABEL_EDITOR::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 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->SetValue( 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:450

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 285 of file unit_binder.cpp.

286 {
287  m_label->Show( aShow );
288  m_value->Show( aShow );
289  m_unitLabel->Show( aShow );
290 
291  if( aResize )
292  {
293  if( aShow )
294  {
295  m_label->SetSize( -1, -1 );
296  m_value->SetSize( -1, -1 );
297  m_unitLabel->SetSize( -1, -1 );
298  }
299  else
300  {
301  m_label->SetSize( 0, 0 );
302  m_value->SetSize( 0, 0 );
303  m_unitLabel->SetSize( 0, 0 );
304  }
305  }
306 }
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_TEXT_PROPERTIES::DIALOG_TEXT_PROPERTIES(), DIALOG_GRAPHIC_ITEM_PROPERTIES::TransferDataToWindow(), and DIALOG_PAD_PRIMITIVES_PROPERTIES::TransferDataToWindow().

◆ Validate()

bool UNIT_BINDER::Validate ( long long int  aMin,
long long 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 149 of file unit_binder.cpp.

150 {
151  auto textEntry = dynamic_cast<wxTextEntry*>( m_value );
152 
153  if( !textEntry || textEntry->GetValue() == INDETERMINATE )
154  return true;
155 
156  if( GetValue() < aMin )
157  {
158  m_errorMessage = wxString::Format( _( "%s must be at least %s." ),
160  StringFromValue( m_units, aMin, true ) );
161 
162  if( setFocusOnError )
163  {
164  textEntry->SelectAll();
165  // Don't focus directly; we might be inside a KillFocus event handler
166  wxPostEvent( this, wxCommandEvent( DELAY_FOCUS ) );
167  }
168 
169  return false;
170  }
171 
172  if( GetValue() > aMax )
173  {
174  m_errorMessage = wxString::Format( _( "%s must be less than %s." ),
176  StringFromValue( m_units, aMax, true ) );
177 
178  if( setFocusOnError )
179  {
180  textEntry->SelectAll();
181  // Don't focus directly; we might be inside a KillFocus event handler
182  wxPostEvent( this, wxCommandEvent( DELAY_FOCUS ) );
183  }
184 
185  return false;
186  }
187 
188  return true;
189 }
wxString m_errorMessage
Validation support.
Definition: unit_binder.h:140
wxWindow * m_value
Definition: unit_binder.h:132
wxString valueDescriptionFromLabel(wxStaticText *aLabel)
#define INDETERMINATE
wxStaticText * m_label
The bound widgets
Definition: unit_binder.h:131
#define _(s)
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
virtual long long int GetValue()
Function GetValue Returns the current value in Internal Units.
wxString StringFromValue(EDA_UNITS_T aUnits, double aValue, bool aAddUnitSymbol, bool aUseMils)
Function StringFromValue returns the string from aValue according to units (inch, mm ....
Definition: base_units.cpp:217

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

Referenced by DIALOG_PNS_LENGTH_TUNING_SETTINGS::AcceptOptions(), DIALOG_COPPER_ZONE::AcceptOptions(), DIALOG_PAGES_SETTINGS::OnOkClick(), DIALOG_TRACK_VIA_PROPERTIES::TransferDataFromWindow(), DIALOG_SET_GRID::TransferDataFromWindow(), DIALOG_TARGET_PROPERTIES::TransferDataFromWindow(), DIALOG_NON_COPPER_ZONES_EDITOR::TransferDataFromWindow(), DIALOG_TEXT_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_selEnd

long UNIT_BINDER::m_selEnd
protected

Definition at line 149 of file unit_binder.h.

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

◆ m_selStart

long UNIT_BINDER::m_selStart
protected

Selection start and end of the original text

Definition at line 148 of file unit_binder.h.

Referenced by 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: