KiCad PCB EDA Suite
Loading...
Searching...
No Matches
UNIT_BINDER Class Reference

#include <unit_binder.h>

Inheritance diagram for UNIT_BINDER:
PROPERTY_EDITOR_UNIT_BINDER

Public Member Functions

 UNIT_BINDER (EDA_DRAW_FRAME *aParent, wxStaticText *aLabel, wxWindow *aValueCtrl, wxStaticText *aUnitLabel, bool aAllowEval=true, bool aBindFocusEvent=true)
 
 UNIT_BINDER (UNITS_PROVIDER *aUnitsProvider, wxWindow *aEventSource, wxStaticText *aLabel, wxWindow *aValueCtrl, wxStaticText *aUnitLabel, bool aAllowEval=true, bool aBindFocusEvent=true)
 
virtual ~UNIT_BINDER () override
 
virtual void SetUnits (EDA_UNITS aUnits)
 Normally not needed (as the UNIT_BINDER inherits from the parent frame), but can be used to set to DEGREES for angular controls.
 
bool UnitsInvariant () const
 
virtual void SetNegativeZero ()
 
virtual void SetPrecision (int aLength)
 Normally not needed, but can be used to set the precision when using internal units that are floats (not integers) like DEGREES or PERCENT.
 
void SetDataType (EDA_DATA_TYPE aDataType)
 Used to override the datatype of the displayed property (default is DISTANCE)
 
virtual void SetValue (long long int aValue)
 Set new value (in Internal Units) for the text field, taking care of units conversion.
 
void SetValue (const wxString &aValue)
 
virtual void SetDoubleValue (double aValue)
 Set new value (in Internal Units) for the text field, taking care of units conversion.
 
virtual void SetAngleValue (const EDA_ANGLE &aValue)
 
virtual void ChangeValue (int aValue)
 Set new value (in Internal Units) for the text field, taking care of units conversion WITHOUT triggering the update routine.
 
void ChangeValue (const wxString &aValue)
 
virtual void ChangeDoubleValue (double aValue)
 Set new value (in Internal Units) for the text field, taking care of units conversion WITHOUT triggering the update routine.
 
virtual void ChangeAngleValue (const EDA_ANGLE &aValue)
 
virtual long long int GetValue () const
 Return the current value in Internal Units.
 
int GetIntValue () const
 
virtual double GetDoubleValue () const
 Return the current value in Internal Units.
 
virtual EDA_ANGLE GetAngleValue ()
 
virtual void SetOptionsList (std::span< const long long int > aOptions)
 Set the list of options for a combobox control.
 
virtual void SetDoubleOptionsList (std::span< const double > aOptions)
 
bool IsIndeterminate () const
 Return true if the control holds the indeterminate value (for instance, if it represents a multiple selection of differing values).
 
bool IsNull () const
 Return true if the control holds no value (ie: empty string, not 0).
 
void SetNull ()
 
virtual bool Validate (double aMin, double aMax, EDA_UNITS aUnits=EDA_UNITS::UNSCALED)
 Validate the control against the given range, informing the user of any errors found.
 
void SetLabel (const wxString &aLabel)
 
void Enable (bool aEnable)
 Enable/disable the label, widget and units label.
 
void Show (bool aShow, bool aResize=false)
 Show/hide the label, widget and units label.
 
ORIGIN_TRANSFORMS::COORD_TYPES_T GetCoordType () const
 Get the origin transforms coordinate type.
 
void SetCoordType (ORIGIN_TRANSFORMS::COORD_TYPES_T aCoordType)
 Set the current origin transform mode.
 
void RequireEval ()
 Force the binder to evaluate the text.
 

Protected Member Functions

void onClick (wxMouseEvent &aEvent)
 
void onComboBox (wxCommandEvent &aEvent)
 
void onSetFocus (wxFocusEvent &aEvent)
 
void onKillFocus (wxFocusEvent &aEvent)
 
void delayedFocusHandler (wxCommandEvent &aEvent)
 
void onUnitsChanged (wxCommandEvent &aEvent)
 
double setPrecision (double aValue, bool aValueUsesUserUnits) const
 When m_precision > 0 truncate the value aValue to show only m_precision digits in mantissa.
 
wxString getTextForValue (long long int aValue) const
 
wxString getTextForDoubleValue (double aValue) const
 

Protected Attributes

bool m_bindFocusEvent
 
wxStaticText * m_label
 The bound widgets.
 
wxWindow * m_valueCtrl
 
wxWindow * m_eventSource
 
wxStaticText * m_unitLabel
 Can be nullptr.
 
const EDA_IU_SCALEm_iuScale
 Currently used units.
 
EDA_UNITS m_units
 
bool m_negativeZero
 Indicates "-0" should be displayed for 0.
 
EDA_DATA_TYPE m_dataType
 
int m_precision
 0 to 6.
 
wxString m_errorMessage
 
NUMERIC_EVALUATOR m_eval
 
bool m_allowEval
 
bool m_needsEval
 
long m_selStart
 Selection start and end of the original text.
 
long m_selEnd
 
bool m_unitsInValue
 Units label should be included in value text.
 
ORIGIN_TRANSFORMSm_originTransforms
 A reference to an ORIGIN_TRANSFORMS object.
 
ORIGIN_TRANSFORMS::COORD_TYPES_T m_coordType
 Type of coordinate for display origin transforms.
 

Detailed Description

Definition at line 42 of file unit_binder.h.

Constructor & Destructor Documentation

◆ UNIT_BINDER() [1/2]

UNIT_BINDER::UNIT_BINDER ( EDA_DRAW_FRAME * aParent,
wxStaticText * aLabel,
wxWindow * aValueCtrl,
wxStaticText * aUnitLabel,
bool aAllowEval = true,
bool aBindFocusEvent = true )
Parameters
aParentis the parent EDA_BASE_FRAME, used to fetch units and coordinate systems.
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)
aValueCtrlis the control used to edit or display the given value (wxTextCtrl, wxComboBox, wxStaticText, etc.).
aUnitLabel(optional) is the units label displayed after the text input widget
aAllowEvalindicates aTextInput's content should be eval'ed before storing
aBindFocusEventindicates the control should respond to DELAY_FOCUS from the parent frame

Definition at line 44 of file unit_binder.cpp.

References UNIT_BINDER().

Referenced by PROPERTY_EDITOR_UNIT_BINDER::PROPERTY_EDITOR_UNIT_BINDER(), and UNIT_BINDER().

◆ UNIT_BINDER() [2/2]

UNIT_BINDER::UNIT_BINDER ( UNITS_PROVIDER * aUnitsProvider,
wxWindow * aEventSource,
wxStaticText * aLabel,
wxWindow * aValueCtrl,
wxStaticText * aUnitLabel,
bool aAllowEval = true,
bool aBindFocusEvent = true )

◆ ~UNIT_BINDER()

UNIT_BINDER::~UNIT_BINDER ( )
overridevirtual

Member Function Documentation

◆ ChangeAngleValue()

void UNIT_BINDER::ChangeAngleValue ( const EDA_ANGLE & aValue)
virtual

Definition at line 489 of file unit_binder.cpp.

References EDA_ANGLE::AsDegrees(), and ChangeDoubleValue().

◆ ChangeDoubleValue()

void UNIT_BINDER::ChangeDoubleValue ( double aValue)
virtual

Set new value (in Internal Units) for the text field, taking care of units conversion WITHOUT triggering the update routine.

The value will be truncated according to the precision set by SetPrecision() (if not <= 0).

Definition at line 483 of file unit_binder.cpp.

References ChangeValue(), and getTextForDoubleValue().

Referenced by ChangeAngleValue().

◆ ChangeValue() [1/2]

void UNIT_BINDER::ChangeValue ( const wxString & aValue)

◆ ChangeValue() [2/2]

void UNIT_BINDER::ChangeValue ( int aValue)
virtual

Set new value (in Internal Units) for the text field, taking care of units conversion WITHOUT triggering the update routine.

Definition at line 477 of file unit_binder.cpp.

References ChangeValue(), and getTextForValue().

Referenced by ChangeDoubleValue(), and ChangeValue().

◆ delayedFocusHandler()

void UNIT_BINDER::delayedFocusHandler ( wxCommandEvent & aEvent)
protected

Definition at line 334 of file unit_binder.cpp.

References DisplayErrorMessage(), m_errorMessage, and m_valueCtrl.

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

◆ Enable()

void UNIT_BINDER::Enable ( bool aEnable)

Enable/disable the label, widget and units label.

Definition at line 666 of file unit_binder.cpp.

References m_label, m_unitLabel, and m_valueCtrl.

◆ GetAngleValue()

EDA_ANGLE UNIT_BINDER::GetAngleValue ( )
virtual

Definition at line 603 of file unit_binder.cpp.

References DEGREES_T, and GetDoubleValue().

◆ GetCoordType()

ORIGIN_TRANSFORMS::COORD_TYPES_T UNIT_BINDER::GetCoordType ( ) const
inline

Get the origin transforms coordinate type.

Returns
the origin transforms coordinate type.

Definition at line 197 of file unit_binder.h.

References m_coordType.

◆ GetDoubleValue()

double UNIT_BINDER::GetDoubleValue ( ) const
virtual

Return the current value in Internal Units.

The returned value will be truncated according to the precision set by SetPrecision() (if not <= 0).

Definition at line 572 of file unit_binder.cpp.

References EDA_UNIT_UTILS::UI::DoubleValueFromString(), m_coordType, m_dataType, m_eval, m_iuScale, m_needsEval, m_originTransforms, m_units, m_valueCtrl, and setPrecision().

Referenced by GetAngleValue().

◆ GetIntValue()

int UNIT_BINDER::GetIntValue ( ) const
inline

Definition at line 134 of file unit_binder.h.

References GetValue().

Referenced by onUnitsChanged().

◆ getTextForDoubleValue()

wxString UNIT_BINDER::getTextForDoubleValue ( double aValue) const
protected

◆ getTextForValue()

wxString UNIT_BINDER::getTextForValue ( long long int aValue) const
protected

◆ GetValue()

long long int UNIT_BINDER::GetValue ( ) const
virtual

Return the current value in Internal Units.

Definition at line 523 of file unit_binder.cpp.

References m_coordType, m_dataType, m_eval, m_iuScale, m_needsEval, m_originTransforms, m_units, m_valueCtrl, and EDA_UNIT_UTILS::UI::ValueFromString().

Referenced by GetIntValue(), WX_MULTI_ENTRY_DIALOG::GetValues(), and Validate().

◆ IsIndeterminate()

bool UNIT_BINDER::IsIndeterminate ( ) const

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

Definition at line 633 of file unit_binder.cpp.

References INDETERMINATE_ACTION, INDETERMINATE_STATE, and m_valueCtrl.

Referenced by onUnitsChanged().

◆ IsNull()

bool UNIT_BINDER::IsNull ( ) const

Return true if the control holds no value (ie: empty string, not 0).

Definition at line 644 of file unit_binder.cpp.

References m_valueCtrl.

◆ onClick()

void UNIT_BINDER::onClick ( wxMouseEvent & aEvent)
protected

◆ onComboBox()

void UNIT_BINDER::onComboBox ( wxCommandEvent & aEvent)
protected

◆ onKillFocus()

void UNIT_BINDER::onKillFocus ( wxFocusEvent & aEvent)
protected

◆ onSetFocus()

void UNIT_BINDER::onSetFocus ( wxFocusEvent & aEvent)
protected

◆ onUnitsChanged()

◆ RequireEval()

void UNIT_BINDER::RequireEval ( )
inline

Force the binder to evaluate the text.

Definition at line 213 of file unit_binder.h.

References m_needsEval.

◆ SetAngleValue()

void UNIT_BINDER::SetAngleValue ( const EDA_ANGLE & aValue)
virtual

Definition at line 416 of file unit_binder.cpp.

References EDA_ANGLE::AsDegrees(), and SetDoubleValue().

◆ SetCoordType()

void UNIT_BINDER::SetCoordType ( ORIGIN_TRANSFORMS::COORD_TYPES_T aCoordType)
inline

Set the current origin transform mode.

Definition at line 205 of file unit_binder.h.

References m_coordType.

◆ SetDataType()

void UNIT_BINDER::SetDataType ( EDA_DATA_TYPE aDataType)

Used to override the datatype of the displayed property (default is DISTANCE)

Parameters
aDataTypeis the datatype to use for the units text display

Definition at line 166 of file unit_binder.cpp.

References EDA_UNIT_UTILS::GetLabel(), m_dataType, m_unitLabel, and m_units.

◆ SetDoubleOptionsList()

void UNIT_BINDER::SetDoubleOptionsList ( std::span< const double > aOptions)
virtual

Definition at line 621 of file unit_binder.cpp.

References getTextForDoubleValue(), and m_valueCtrl.

◆ SetDoubleValue()

void UNIT_BINDER::SetDoubleValue ( double aValue)
virtual

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

The value will be truncated according to the precision set by SetPrecision() (if not <= 0).

Definition at line 403 of file unit_binder.cpp.

References m_coordType, m_dataType, m_iuScale, m_negativeZero, m_originTransforms, m_units, setPrecision(), SetValue(), and EDA_UNIT_UTILS::UI::StringFromValue().

Referenced by SetAngleValue().

◆ SetLabel()

void UNIT_BINDER::SetLabel ( const wxString & aLabel)

Definition at line 660 of file unit_binder.cpp.

References m_label.

◆ SetNegativeZero()

virtual void UNIT_BINDER::SetNegativeZero ( )
inlinevirtual

Definition at line 78 of file unit_binder.h.

References m_negativeZero.

◆ SetNull()

void UNIT_BINDER::SetNull ( )

Definition at line 653 of file unit_binder.cpp.

References m_valueCtrl.

◆ SetOptionsList()

void UNIT_BINDER::SetOptionsList ( std::span< const long long int > aOptions)
virtual

Set the list of options for a combobox control.

Doesn't affect the value of the control.

Definition at line 609 of file unit_binder.cpp.

References getTextForValue(), and m_valueCtrl.

Referenced by DIALOG_OUTSET_ITEMS::DIALOG_OUTSET_ITEMS(), and onUnitsChanged().

◆ SetPrecision()

void UNIT_BINDER::SetPrecision ( int aLength)
virtual

Normally not needed, but can be used to set the precision when using internal units that are floats (not integers) like DEGREES or PERCENT.

Not used for integer values in IU

Parameters
aLengthis the number of digits for mantissa (0 = no truncation) must be <= 6

Definition at line 160 of file unit_binder.cpp.

References m_precision.

◆ setPrecision()

double UNIT_BINDER::setPrecision ( double aValue,
bool aValueUsesUserUnits ) const
protected

When m_precision > 0 truncate the value aValue to show only m_precision digits in mantissa.

used in GetDoubleValue to return a rounded value. Mainly for units set to DEGREES.

Parameters
aValueis the value to modify.
aValueUsesUserUnitsmust be set to true if aValue is a user value, and set to false if aValue is a internal unit value.
Returns
the "rounded" value.

Definition at line 552 of file unit_binder.cpp.

References EDA_UNIT_UTILS::UI::FromUserUnit(), m_iuScale, m_precision, m_units, scale, and EDA_UNIT_UTILS::UI::ToUserUnit().

Referenced by GetDoubleValue(), getTextForDoubleValue(), getTextForValue(), and SetDoubleValue().

◆ SetUnits()

void UNIT_BINDER::SetUnits ( EDA_UNITS aUnits)
virtual

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

References EDA_UNIT_UTILS::GetLabel(), m_dataType, m_eval, m_unitLabel, and m_units.

Referenced by onUnitsChanged().

◆ SetValue() [1/2]

void UNIT_BINDER::SetValue ( const wxString & aValue)

◆ SetValue() [2/2]

void UNIT_BINDER::SetValue ( long long int aValue)
virtual

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

Definition at line 391 of file unit_binder.cpp.

References m_coordType, m_dataType, m_iuScale, m_negativeZero, m_originTransforms, m_units, SetValue(), and EDA_UNIT_UTILS::UI::StringFromValue().

Referenced by onComboBox(), onUnitsChanged(), SetDoubleValue(), and SetValue().

◆ Show()

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

Show/hide 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 678 of file unit_binder.cpp.

References m_label, m_unitLabel, and m_valueCtrl.

◆ UnitsInvariant()

bool UNIT_BINDER::UnitsInvariant ( ) const
inline

Definition at line 73 of file unit_binder.h.

References DEGREES, m_units, PERCENT, and UNSCALED.

Referenced by onUnitsChanged().

◆ Validate()

bool UNIT_BINDER::Validate ( double aMin,
double aMax,
EDA_UNITS aUnits = EDA_UNITS::UNSCALED )
virtual

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

Parameters
aMina minimum value for validation.
aMaxa maximum value for validation.
aUnitsthe units of the min/max parameters (use UNSCALED for internal units).
Returns
false on error.

Definition at line 344 of file unit_binder.cpp.

References _, EDA_UNIT_UTILS::UI::FromUserUnit(), GetValue(), INDETERMINATE_ACTION, INDETERMINATE_STATE, m_errorMessage, m_iuScale, m_label, m_units, m_valueCtrl, EDA_UNIT_UTILS::UI::StringFromValue(), and valueDescriptionFromLabel().

Referenced by validateMM().

Member Data Documentation

◆ m_allowEval

bool UNIT_BINDER::m_allowEval
protected

Definition at line 263 of file unit_binder.h.

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

◆ m_bindFocusEvent

bool UNIT_BINDER::m_bindFocusEvent
protected

Definition at line 245 of file unit_binder.h.

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

◆ m_coordType

ORIGIN_TRANSFORMS::COORD_TYPES_T UNIT_BINDER::m_coordType
protected

Type of coordinate for display origin transforms.

Definition at line 275 of file unit_binder.h.

Referenced by GetCoordType(), GetDoubleValue(), getTextForDoubleValue(), getTextForValue(), GetValue(), SetCoordType(), SetDoubleValue(), SetValue(), and UNIT_BINDER().

◆ m_dataType

◆ m_errorMessage

wxString UNIT_BINDER::m_errorMessage
protected

Definition at line 260 of file unit_binder.h.

Referenced by delayedFocusHandler(), and Validate().

◆ m_eval

NUMERIC_EVALUATOR UNIT_BINDER::m_eval
mutableprotected

◆ m_eventSource

wxWindow* UNIT_BINDER::m_eventSource
protected

Definition at line 250 of file unit_binder.h.

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

◆ m_iuScale

const EDA_IU_SCALE* UNIT_BINDER::m_iuScale
protected

◆ m_label

wxStaticText* UNIT_BINDER::m_label
protected

The bound widgets.

Definition at line 248 of file unit_binder.h.

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

◆ m_needsEval

bool UNIT_BINDER::m_needsEval
protected

◆ m_negativeZero

bool UNIT_BINDER::m_negativeZero
protected

Indicates "-0" should be displayed for 0.

Definition at line 256 of file unit_binder.h.

Referenced by getTextForDoubleValue(), getTextForValue(), SetDoubleValue(), SetNegativeZero(), SetValue(), and UNIT_BINDER().

◆ m_originTransforms

ORIGIN_TRANSFORMS& UNIT_BINDER::m_originTransforms
protected

◆ m_precision

int UNIT_BINDER::m_precision
protected

0 to 6.

Definition at line 258 of file unit_binder.h.

Referenced by SetPrecision(), setPrecision(), and UNIT_BINDER().

◆ m_selEnd

long UNIT_BINDER::m_selEnd
protected

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

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

◆ m_unitLabel

wxStaticText* UNIT_BINDER::m_unitLabel
protected

Can be nullptr.

Definition at line 251 of file unit_binder.h.

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

◆ m_units

◆ m_unitsInValue

bool UNIT_BINDER::m_unitsInValue
protected

Units label should be included in value text.

Definition at line 269 of file unit_binder.h.

Referenced by ChangeValue(), onKillFocus(), PROPERTY_EDITOR_UNIT_BINDER::PROPERTY_EDITOR_UNIT_BINDER(), SetValue(), and UNIT_BINDER().

◆ m_valueCtrl


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