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 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 SetDoubleValue (double aValue)
 Function SetDoubleValue Sets new value (in Internal Units) for the text field, taking care of units conversion. More...
 
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...
 
virtual double GetDoubleValue ()
 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 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:145
bool m_needsEval
Definition: unit_binder.h:158
wxString GetAbbreviatedUnitsLabel(EDA_UNITS aUnit, bool aUseMils, EDA_DATA_TYPE aType)
Get the units string for a given units type.
Definition: base_units.cpp:467
EDA_UNITS m_units
Currently used units.
Definition: unit_binder.h:149
#define NULL
wxStaticText * m_label
The bound widgets
Definition: unit_binder.h:144
wxStaticText * m_unitLabel
Definition: unit_binder.h:146
NUMERIC_EVALUATOR m_eval
Evaluator
Definition: unit_binder.h:156
bool m_useMils
Definition: unit_binder.h:150
bool m_allowEval
Definition: unit_binder.h:157
void onKillFocus(wxFocusEvent &aEvent)
Definition: unit_binder.cpp:97
void onSetFocus(wxFocusEvent &aEvent)
Definition: unit_binder.cpp:76
long m_selStart
Selection start and end of the original text
Definition: unit_binder.h:161
EDA_UNITS GetUserUnits() const
Return the user units currently in use.

References delayedFocusHandler(), GetAbbreviatedUnitsLabel(), EDA_BASE_FRAME::GetUserUnits(), m_allowEval, m_needsEval, m_selEnd, m_selStart, m_unitLabel, m_units, m_useMils, m_value, NULL, 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 221 of file unit_binder.cpp.

222 {
223  ChangeValue( StringFromValue( m_units, aValue, false, m_useMils ) );
224 }
wxString StringFromValue(EDA_UNITS aUnits, double aValue, bool aAddUnitSymbol, bool aUseMils)
Function StringFromValue returns the string from aValue according to units (inch, mm ....
Definition: base_units.cpp:234
EDA_UNITS m_units
Currently used units.
Definition: unit_binder.h:149
bool m_useMils
Definition: unit_binder.h:150
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 227 of file unit_binder.cpp.

228 {
229  auto textEntry = dynamic_cast<wxTextEntry*>( m_value );
230  auto staticText = dynamic_cast<wxStaticText*>( m_value );
231 
232  if( textEntry )
233  textEntry->ChangeValue( aValue );
234  else if( staticText )
235  staticText->SetLabel( aValue );
236 
237  if( m_allowEval )
238  m_eval.Clear();
239 
241 }
wxWindow * m_value
Definition: unit_binder.h:145
wxString GetAbbreviatedUnitsLabel(EDA_UNITS aUnit, bool aUseMils, EDA_DATA_TYPE aType)
Get the units string for a given units type.
Definition: base_units.cpp:467
EDA_UNITS m_units
Currently used units.
Definition: unit_binder.h:149
wxStaticText * m_unitLabel
Definition: unit_binder.h:146
NUMERIC_EVALUATOR m_eval
Evaluator
Definition: unit_binder.h:156
bool m_useMils
Definition: unit_binder.h:150
bool m_allowEval
Definition: unit_binder.h:157

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:239
wxString m_errorMessage
Validation support.
Definition: unit_binder.h:153
wxWindow * m_value
Definition: unit_binder.h:145

References DisplayError(), m_errorMessage, and m_value.

Referenced by UNIT_BINDER().

◆ Enable()

void UNIT_BINDER::Enable ( bool  aEnable)

Function Enable Enables/diasables the label, widget and units label.

Definition at line 305 of file unit_binder.cpp.

306 {
307  m_label->Enable( aEnable );
308  m_value->Enable( aEnable );
309  m_unitLabel->Enable( aEnable );
310 }
wxWindow * m_value
Definition: unit_binder.h:145
wxStaticText * m_label
The bound widgets
Definition: unit_binder.h:144
wxStaticText * m_unitLabel
Definition: unit_binder.h:146

References m_label, m_unitLabel, and m_value.

Referenced by DIALOG_PAD_PROPERTIES::initValues(), DIALOG_PAD_PROPERTIES::OnPadShapeSelection(), DIALOG_PAGES_SETTINGS::OnPaperSizeChoice(), DIALOG_TRACK_VIA_PROPERTIES::onTrackNetclassCheck(), DIALOG_PLOT_SCHEMATIC::OnUpdateUI(), DIALOG_EDIT_COMPONENT_IN_LIBRARY::OnUpdateUI(), DIALOG_PAD_PROPERTIES::OnUpdateUI(), DIALOG_TRACK_VIA_PROPERTIES::onViaNetclassCheck(), and DIALOG_PLOT::SetPlotFormat().

◆ GetDoubleValue()

double UNIT_BINDER::GetDoubleValue ( )
virtual

Function GetValue Returns the current value in Internal Units.

Definition at line 266 of file unit_binder.cpp.

267 {
268  auto textEntry = dynamic_cast<wxTextEntry*>( m_value );
269  auto staticText = dynamic_cast<wxStaticText*>( m_value );
270  wxString value;
271 
272  if( textEntry )
273  {
274  if( m_needsEval && m_eval.Process( textEntry->GetValue() ) )
275  value = m_eval.Result();
276  else
277  value = textEntry->GetValue();
278  }
279  else if( staticText )
280  value = staticText->GetLabel();
281  else
282  return 0.0;
283 
284  return DoubleValueFromString( m_units, value, m_useMils );
285 }
wxWindow * m_value
Definition: unit_binder.h:145
bool m_needsEval
Definition: unit_binder.h:158
EDA_UNITS m_units
Currently used units.
Definition: unit_binder.h:149
bool Process(const wxString &aString)
NUMERIC_EVALUATOR m_eval
Evaluator
Definition: unit_binder.h:156
bool m_useMils
Definition: unit_binder.h:150
wxString Result() const
double DoubleValueFromString(EDA_UNITS aUnits, const wxString &aTextValue, bool aUseMils)
Function DoubleValueFromString converts aTextValue to a double.
Definition: base_units.cpp:331

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

Referenced by DIALOG_POSITION_RELATIVE::GetTranslationInIU(), DIALOG_MOVE_EXACT::GetTranslationInIU(), DIALOG_POSITION_RELATIVE::OnClear(), DIALOG_POSITION_RELATIVE::OnOkClick(), DIALOG_POSITION_RELATIVE::OnPolarChanged(), DIALOG_MOVE_EXACT::OnPolarChanged(), DIALOG_MOVE_EXACT::OnTextChanged(), and DIALOG_MOVE_EXACT::TransferDataFromWindow().

◆ GetValue()

long long int UNIT_BINDER::GetValue ( )
virtual

Function GetValue Returns the current value in Internal Units.

Definition at line 244 of file unit_binder.cpp.

245 {
246  auto textEntry = dynamic_cast<wxTextEntry*>( m_value );
247  auto staticText = dynamic_cast<wxStaticText*>( m_value );
248  wxString value;
249 
250  if( textEntry )
251  {
252  if( m_needsEval && m_eval.Process( textEntry->GetValue() ) )
253  value = m_eval.Result();
254  else
255  value = textEntry->GetValue();
256  }
257  else if( staticText )
258  value = staticText->GetLabel();
259  else
260  return 0;
261 
262  return ValueFromString( m_units, value, m_useMils );
263 }
wxWindow * m_value
Definition: unit_binder.h:145
bool m_needsEval
Definition: unit_binder.h:158
EDA_UNITS m_units
Currently used units.
Definition: unit_binder.h:149
bool Process(const wxString &aString)
NUMERIC_EVALUATOR m_eval
Evaluator
Definition: unit_binder.h:156
bool m_useMils
Definition: unit_binder.h:150
wxString Result() const
long long int ValueFromString(EDA_UNITS aUnits, const wxString &aTextValue, bool aUseMils)
Function ValueFromString converts aTextValue in aUnits to internal units used by the application.
Definition: base_units.cpp:444

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_LIB_NEW_COMPONENT::GetPinTextPosition(), DIALOG_PLOT_SCHEMATIC::getPlotOptions(), DIALOG_LIB_EDIT_DRAW_ITEM::GetWidth(), DIALOG_PAD_PRIMITIVE_POLY_PROPS::onCellChanging(), DIALOG_PAD_PROPERTIES::onCornerRadiusChange(), DIALOG_LIB_EDIT_PIN::OnPropertiesChange(), DIALOG_PAD_PROPERTIES::PadTypeSelected(), DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS::processItem(), DIALOG_DRC::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_SETUP_FORMATTING::TransferDataFromWindow(), DIALOG_PNS_LENGTH_TUNING_SETTINGS::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(), DIALOG_SCH_SHEET_PROPS::TransferDataFromWindow(), PANEL_SETUP_FEATURE_CONSTRAINTS::TransferDataFromWindow(), DIALOG_CREATE_ARRAY::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_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 288 of file unit_binder.cpp.

289 {
290  auto textEntry = dynamic_cast<wxTextEntry*>( m_value );
291 
292  if( textEntry )
293  return textEntry->GetValue() == INDETERMINATE;
294 
295  return false;
296 }
wxWindow * m_value
Definition: unit_binder.h:145
#define INDETERMINATE

References INDETERMINATE, and m_value.

Referenced by DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS::processItem(), DIALOG_TRACK_VIA_PROPERTIES::TransferDataFromWindow(), DIALOG_EDIT_LINE_STYLE::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:145
bool m_needsEval
Definition: unit_binder.h:158
bool Process(const wxString &aString)
NUMERIC_EVALUATOR m_eval
Evaluator
Definition: unit_binder.h:156
bool m_allowEval
Definition: unit_binder.h:157
wxString Result() const
long m_selStart
Selection start and end of the original text
Definition: unit_binder.h:161

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:145
wxString OriginalText() const
bool m_needsEval
Definition: unit_binder.h:158
NUMERIC_EVALUATOR m_eval
Evaluator
Definition: unit_binder.h:156
bool m_allowEval
Definition: unit_binder.h:157
long m_selStart
Selection start and end of the original text
Definition: unit_binder.h:161

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

Referenced by UNIT_BINDER().

◆ SetDoubleValue()

void UNIT_BINDER::SetDoubleValue ( double  aValue)
virtual

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

Parameters
aValueis the new value.

Definition at line 198 of file unit_binder.cpp.

199 {
200  SetValue( StringFromValue( m_units, aValue, false, m_useMils ) );
201 }
wxString StringFromValue(EDA_UNITS aUnits, double aValue, bool aAddUnitSymbol, bool aUseMils)
Function StringFromValue returns the string from aValue according to units (inch, mm ....
Definition: base_units.cpp:234
EDA_UNITS m_units
Currently used units.
Definition: unit_binder.h:149
bool m_useMils
Definition: unit_binder.h:150
virtual void SetValue(int aValue)
Function SetValue Sets new value (in Internal Units) for the text field, taking care of units convers...

References m_units, m_useMils, SetValue(), and StringFromValue().

Referenced by DIALOG_MOVE_EXACT::DIALOG_MOVE_EXACT(), DIALOG_POSITION_RELATIVE::DIALOG_POSITION_RELATIVE(), DIALOG_POSITION_RELATIVE::OnClear(), DIALOG_POSITION_RELATIVE::OnPolarChanged(), and DIALOG_MOVE_EXACT::OnPolarChanged().

◆ SetLabel()

void UNIT_BINDER::SetLabel ( const wxString &  aLabel)

Definition at line 299 of file unit_binder.cpp.

300 {
301  m_label->SetLabel( aLabel );
302 }
wxStaticText * m_label
The bound widgets
Definition: unit_binder.h:144

References m_label.

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

◆ SetUnits()

void UNIT_BINDER::SetUnits ( EDA_UNITS  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 }
wxString StringFromValue(EDA_UNITS aUnits, double aValue, bool aAddUnitSymbol, bool aUseMils)
Function StringFromValue returns the string from aValue according to units (inch, mm ....
Definition: base_units.cpp:234
EDA_UNITS m_units
Currently used units.
Definition: unit_binder.h:149
bool m_useMils
Definition: unit_binder.h:150
virtual void SetValue(int aValue)
Function SetValue Sets new value (in Internal Units) for the text field, taking care of units convers...

References m_units, m_useMils, and StringFromValue().

Referenced by DIALOG_COPPER_ZONE::AcceptOptions(), DIALOG_PLOT::applyPlotSettings(), DIALOG_CREATE_ARRAY::calculateCircularArrayProperties(), DIALOG_LIB_NEW_COMPONENT::DIALOG_LIB_NEW_COMPONENT(), DIALOG_MOVE_EXACT::DIALOG_MOVE_EXACT(), DIALOG_TRACK_VIA_PROPERTIES::DIALOG_TRACK_VIA_PROPERTIES(), DIALOG_DRC::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_SET_GRID::OnResetGridOrgClick(), DIALOG_PAD_PROPERTIES::PadTypeSelected(), DIALOG_EDIT_LINE_STYLE::resetDefaults(), SetDoubleValue(), DIALOG_LIB_NEW_COMPONENT::SetPinTextPosition(), DIALOG_EDIT_LINE_STYLE::TransferDataToWindow(), DIALOG_TRACK_VIA_SIZE::TransferDataToWindow(), PANEL_SETUP_FORMATTING::TransferDataToWindow(), DIALOG_LIB_EDIT_DRAW_ITEM::TransferDataToWindow(), DIALOG_PNS_DIFF_PAIR_DIMENSIONS::TransferDataToWindow(), DIALOG_PNS_LENGTH_TUNING_SETTINGS::TransferDataToWindow(), DIALOG_EDIT_SHEET_PIN::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_SCH_SHEET_PROPS::TransferDataToWindow(), DIALOG_EDIT_ONE_FIELD::TransferDataToWindow(), PANEL_SETUP_FEATURE_CONSTRAINTS::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_LABEL_EDITOR::TransferDataToWindow(), DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS::TransferDataToWindow(), DIALOG_FOOTPRINT_BOARD_EDITOR::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 204 of file unit_binder.cpp.

205 {
206  auto textEntry = dynamic_cast<wxTextEntry*>( m_value );
207  auto staticText = dynamic_cast<wxStaticText*>( m_value );
208 
209  if( textEntry )
210  textEntry->SetValue( aValue );
211  else if( staticText )
212  staticText->SetLabel( aValue );
213 
214  if( m_allowEval )
215  m_eval.Clear();
216 
218 }
wxWindow * m_value
Definition: unit_binder.h:145
wxString GetAbbreviatedUnitsLabel(EDA_UNITS aUnit, bool aUseMils, EDA_DATA_TYPE aType)
Get the units string for a given units type.
Definition: base_units.cpp:467
EDA_UNITS m_units
Currently used units.
Definition: unit_binder.h:149
wxStaticText * m_unitLabel
Definition: unit_binder.h:146
NUMERIC_EVALUATOR m_eval
Evaluator
Definition: unit_binder.h:156
bool m_useMils
Definition: unit_binder.h:150
bool m_allowEval
Definition: unit_binder.h:157

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

314 {
315  m_label->Show( aShow );
316  m_value->Show( aShow );
317  m_unitLabel->Show( aShow );
318 
319  if( aResize )
320  {
321  if( aShow )
322  {
323  m_label->SetSize( -1, -1 );
324  m_value->SetSize( -1, -1 );
325  m_unitLabel->SetSize( -1, -1 );
326  }
327  else
328  {
329  m_label->SetSize( 0, 0 );
330  m_value->SetSize( 0, 0 );
331  m_unitLabel->SetSize( 0, 0 );
332  }
333  }
334 }
wxWindow * m_value
Definition: unit_binder.h:145
wxStaticText * m_label
The bound widgets
Definition: unit_binder.h:144
wxStaticText * m_unitLabel
Definition: unit_binder.h:146

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:153
wxWindow * m_value
Definition: unit_binder.h:145
wxString StringFromValue(EDA_UNITS aUnits, double aValue, bool aAddUnitSymbol, bool aUseMils)
Function StringFromValue returns the string from aValue according to units (inch, mm ....
Definition: base_units.cpp:234
wxString valueDescriptionFromLabel(wxStaticText *aLabel)
EDA_UNITS m_units
Currently used units.
Definition: unit_binder.h:149
#define INDETERMINATE
wxStaticText * m_label
The bound widgets
Definition: unit_binder.h:144
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
#define _(s)
Definition: 3d_actions.cpp:33
virtual long long int GetValue()
Function GetValue Returns the current value in Internal Units.

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_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 157 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 153 of file unit_binder.h.

Referenced by delayedFocusHandler(), and Validate().

◆ m_eval

NUMERIC_EVALUATOR UNIT_BINDER::m_eval
protected

Evaluator

Definition at line 156 of file unit_binder.h.

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

◆ m_label

wxStaticText* UNIT_BINDER::m_label
protected

The bound widgets

Definition at line 144 of file unit_binder.h.

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

◆ m_needsEval

bool UNIT_BINDER::m_needsEval
protected

Definition at line 158 of file unit_binder.h.

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

◆ m_selEnd

long UNIT_BINDER::m_selEnd
protected

Definition at line 162 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 161 of file unit_binder.h.

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

◆ m_unitLabel

wxStaticText* UNIT_BINDER::m_unitLabel
protected

Definition at line 146 of file unit_binder.h.

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

◆ m_units

EDA_UNITS UNIT_BINDER::m_units
protected

Currently used units.

Definition at line 149 of file unit_binder.h.

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

◆ m_useMils

bool UNIT_BINDER::m_useMils
protected

◆ m_value

wxWindow* UNIT_BINDER::m_value
protected

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