|
KiCad PCB EDA Suite
|
A specialized binder for combined margin/ratio input fields. More...
#include <margin_offset_binder.h>
Public Member Functions | |
| MARGIN_OFFSET_BINDER (EDA_DRAW_FRAME *aParent, wxStaticText *aLabel, wxWindow *aValueCtrl, wxStaticText *aUnitLabel) | |
| MARGIN_OFFSET_BINDER (UNITS_PROVIDER *aUnitsProvider, wxWindow *aEventSource, wxStaticText *aLabel, wxWindow *aValueCtrl, wxStaticText *aUnitLabel) | |
| virtual | ~MARGIN_OFFSET_BINDER () override |
| void | SetOffsetValue (std::optional< int > aValue) |
| Set the absolute offset value (in Internal Units). | |
| void | SetRatioValue (std::optional< double > aRatio) |
| Set the ratio value as a fraction (e.g., -0.05 for -5%). | |
| std::optional< int > | GetOffsetValue () const |
| Get the absolute offset value (in Internal Units). | |
| std::optional< double > | GetRatioValue () const |
| Get the ratio value as a fraction (e.g., -0.05 for -5%). | |
| bool | IsNull () const |
| Return true if the control holds no value (ie: empty string). | |
| 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. | |
Protected Member Functions | |
| void | onSetFocus (wxFocusEvent &aEvent) |
| void | onKillFocus (wxFocusEvent &aEvent) |
| void | onUnitsChanged (wxCommandEvent &aEvent) |
| bool | parseInput (const wxString &aInput, std::optional< int > &aOffset, std::optional< double > &aRatio) const |
| Parse the input string and extract offset and ratio values. | |
| wxString | formatValue (std::optional< int > aOffset, std::optional< double > aRatio) const |
| Format the offset and ratio values into a display string. | |
| wxString | getTextValue () const |
| Get the current text from the control. | |
| void | setTextValue (const wxString &aValue) |
| Set the text in the control without triggering events. | |
Protected Attributes | |
| wxStaticText * | m_label |
| wxWindow * | m_valueCtrl |
| wxWindow * | m_eventSource |
| wxStaticText * | m_unitLabel |
| Can be nullptr. | |
| const EDA_IU_SCALE * | m_iuScale |
| EDA_UNITS | m_units |
| NUMERIC_EVALUATOR | m_eval |
| std::optional< int > | m_cachedOffset |
| std::optional< double > | m_cachedRatio |
| bool | m_needsParsing |
A specialized binder for combined margin/ratio input fields.
This binder handles input expressions that can contain both an absolute offset value and a percentage ratio, such as: "-2mm + 1%" "0.5mm - 5%" "0.5mm" "-10%"
The final clearance is computed as: absolute_value + (ratio * reference_size)
Definition at line 49 of file margin_offset_binder.h.
| MARGIN_OFFSET_BINDER::MARGIN_OFFSET_BINDER | ( | EDA_DRAW_FRAME * | aParent, |
| wxStaticText * | aLabel, | ||
| wxWindow * | aValueCtrl, | ||
| wxStaticText * | aUnitLabel ) |
| aParent | is the parent EDA_DRAW_FRAME, used to fetch units and coordinate systems. |
| aLabel | is the static text used to label the text input widget |
| aValueCtrl | is the control used to edit the combined value (wxTextCtrl or wxComboBox) |
| aUnitLabel | (optional) is the units label displayed after the text input widget |
Definition at line 35 of file margin_offset_binder.cpp.
References MARGIN_OFFSET_BINDER().
Referenced by MARGIN_OFFSET_BINDER().
| MARGIN_OFFSET_BINDER::MARGIN_OFFSET_BINDER | ( | UNITS_PROVIDER * | aUnitsProvider, |
| wxWindow * | aEventSource, | ||
| wxStaticText * | aLabel, | ||
| wxWindow * | aValueCtrl, | ||
| wxStaticText * | aUnitLabel ) |
Definition at line 42 of file margin_offset_binder.cpp.
References GetUserUnits(), m_cachedOffset, m_cachedRatio, m_eval, m_eventSource, m_iuScale, m_label, m_needsParsing, m_unitLabel, m_units, m_valueCtrl, onKillFocus(), onSetFocus(), and onUnitsChanged().
|
overridevirtual |
Definition at line 79 of file margin_offset_binder.cpp.
References m_eventSource, m_valueCtrl, onKillFocus(), onSetFocus(), and onUnitsChanged().
| void MARGIN_OFFSET_BINDER::Enable | ( | bool | aEnable | ) |
Enable/disable the label, widget and units label.
Definition at line 150 of file margin_offset_binder.cpp.
References m_label, m_unitLabel, and m_valueCtrl.
|
protected |
Format the offset and ratio values into a display string.
Definition at line 385 of file margin_offset_binder.cpp.
References std::abs(), m_iuScale, m_units, result, and EDA_UNIT_UTILS::UI::StringFromValue().
Referenced by onKillFocus(), onUnitsChanged(), SetOffsetValue(), and SetRatioValue().
| std::optional< int > MARGIN_OFFSET_BINDER::GetOffsetValue | ( | ) | const |
Get the absolute offset value (in Internal Units).
Returns std::nullopt if no offset was specified.
Definition at line 116 of file margin_offset_binder.cpp.
References getTextValue(), m_cachedOffset, m_cachedRatio, m_needsParsing, and parseInput().
Referenced by onUnitsChanged().
| std::optional< double > MARGIN_OFFSET_BINDER::GetRatioValue | ( | ) | const |
Get the ratio value as a fraction (e.g., -0.05 for -5%).
Returns std::nullopt if no ratio was specified.
Definition at line 129 of file margin_offset_binder.cpp.
References getTextValue(), m_cachedOffset, m_cachedRatio, m_needsParsing, and parseInput().
Referenced by onUnitsChanged().
|
protected |
Get the current text from the control.
Definition at line 419 of file margin_offset_binder.cpp.
References m_valueCtrl.
Referenced by GetOffsetValue(), GetRatioValue(), IsNull(), and onKillFocus().
| bool MARGIN_OFFSET_BINDER::IsNull | ( | ) | const |
Return true if the control holds no value (ie: empty string).
Definition at line 142 of file margin_offset_binder.cpp.
References getTextValue(), and text.
|
protected |
Definition at line 213 of file margin_offset_binder.cpp.
References formatValue(), getTextValue(), m_cachedOffset, m_cachedRatio, m_needsParsing, parseInput(), and setTextValue().
Referenced by MARGIN_OFFSET_BINDER(), and ~MARGIN_OFFSET_BINDER().
|
protected |
Definition at line 206 of file margin_offset_binder.cpp.
References m_needsParsing.
Referenced by MARGIN_OFFSET_BINDER(), and ~MARGIN_OFFSET_BINDER().
|
protected |
Definition at line 232 of file margin_offset_binder.cpp.
References formatValue(), UNITS_PROVIDER::GetIuScale(), GetOffsetValue(), GetRatioValue(), UNITS_PROVIDER::GetUserUnits(), m_eval, m_iuScale, m_units, and setTextValue().
Referenced by MARGIN_OFFSET_BINDER(), and ~MARGIN_OFFSET_BINDER().
|
protected |
Parse the input string and extract offset and ratio values.
Definition at line 252 of file margin_offset_binder.cpp.
References m_iuScale, m_units, NUMERIC_EVALUATOR::Process(), NUMERIC_EVALUATOR::Result(), result, sign(), and EDA_UNIT_UTILS::UI::ValueFromString().
Referenced by GetOffsetValue(), GetRatioValue(), and onKillFocus().
| void MARGIN_OFFSET_BINDER::SetOffsetValue | ( | std::optional< int > | aValue | ) |
Set the absolute offset value (in Internal Units).
Use std::nullopt to indicate no value is set.
Definition at line 100 of file margin_offset_binder.cpp.
References formatValue(), m_cachedOffset, m_cachedRatio, m_needsParsing, and setTextValue().
| void MARGIN_OFFSET_BINDER::SetRatioValue | ( | std::optional< double > | aRatio | ) |
Set the ratio value as a fraction (e.g., -0.05 for -5%).
Use std::nullopt to indicate no value is set.
Definition at line 108 of file margin_offset_binder.cpp.
References formatValue(), m_cachedOffset, m_cachedRatio, m_needsParsing, and setTextValue().
|
protected |
Set the text in the control without triggering events.
Definition at line 430 of file margin_offset_binder.cpp.
References m_valueCtrl.
Referenced by onKillFocus(), onUnitsChanged(), SetOffsetValue(), and SetRatioValue().
| void MARGIN_OFFSET_BINDER::Show | ( | bool | aShow, |
| bool | aResize = false ) |
Show/hide the label, widget and units label.
Definition at line 163 of file margin_offset_binder.cpp.
References m_label, m_unitLabel, and m_valueCtrl.
|
mutableprotected |
Definition at line 144 of file margin_offset_binder.h.
Referenced by GetOffsetValue(), GetRatioValue(), MARGIN_OFFSET_BINDER(), onKillFocus(), SetOffsetValue(), and SetRatioValue().
|
mutableprotected |
Definition at line 145 of file margin_offset_binder.h.
Referenced by GetOffsetValue(), GetRatioValue(), MARGIN_OFFSET_BINDER(), onKillFocus(), SetOffsetValue(), and SetRatioValue().
|
mutableprotected |
Definition at line 141 of file margin_offset_binder.h.
Referenced by MARGIN_OFFSET_BINDER(), and onUnitsChanged().
|
protected |
Definition at line 135 of file margin_offset_binder.h.
Referenced by MARGIN_OFFSET_BINDER(), and ~MARGIN_OFFSET_BINDER().
|
protected |
Definition at line 138 of file margin_offset_binder.h.
Referenced by formatValue(), MARGIN_OFFSET_BINDER(), onUnitsChanged(), and parseInput().
|
protected |
Definition at line 133 of file margin_offset_binder.h.
Referenced by Enable(), MARGIN_OFFSET_BINDER(), and Show().
|
mutableprotected |
Definition at line 146 of file margin_offset_binder.h.
Referenced by GetOffsetValue(), GetRatioValue(), MARGIN_OFFSET_BINDER(), onKillFocus(), onSetFocus(), SetOffsetValue(), and SetRatioValue().
|
protected |
Can be nullptr.
Definition at line 136 of file margin_offset_binder.h.
Referenced by Enable(), MARGIN_OFFSET_BINDER(), and Show().
|
protected |
Definition at line 139 of file margin_offset_binder.h.
Referenced by formatValue(), MARGIN_OFFSET_BINDER(), onUnitsChanged(), and parseInput().
|
protected |
Definition at line 134 of file margin_offset_binder.h.
Referenced by Enable(), getTextValue(), MARGIN_OFFSET_BINDER(), setTextValue(), Show(), and ~MARGIN_OFFSET_BINDER().