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

A specialized binder for combined margin/ratio input fields. More...

#include <margin_offset_binder.h>

Inheritance diagram for MARGIN_OFFSET_BINDER:

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_SCALEm_iuScale
 
EDA_UNITS m_units
 
NUMERIC_EVALUATOR m_eval
 
std::optional< int > m_cachedOffset
 
std::optional< double > m_cachedRatio
 
bool m_needsParsing
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ MARGIN_OFFSET_BINDER() [1/2]

MARGIN_OFFSET_BINDER::MARGIN_OFFSET_BINDER ( EDA_DRAW_FRAME * aParent,
wxStaticText * aLabel,
wxWindow * aValueCtrl,
wxStaticText * aUnitLabel )
Parameters
aParentis the parent EDA_DRAW_FRAME, used to fetch units and coordinate systems.
aLabelis the static text used to label the text input widget
aValueCtrlis 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() [2/2]

MARGIN_OFFSET_BINDER::MARGIN_OFFSET_BINDER ( UNITS_PROVIDER * aUnitsProvider,
wxWindow * aEventSource,
wxStaticText * aLabel,
wxWindow * aValueCtrl,
wxStaticText * aUnitLabel )

◆ ~MARGIN_OFFSET_BINDER()

MARGIN_OFFSET_BINDER::~MARGIN_OFFSET_BINDER ( )
overridevirtual

Member Function Documentation

◆ Enable()

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.

◆ formatValue()

wxString MARGIN_OFFSET_BINDER::formatValue ( std::optional< int > aOffset,
std::optional< double > aRatio ) const
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().

◆ GetOffsetValue()

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().

◆ GetRatioValue()

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().

◆ getTextValue()

wxString MARGIN_OFFSET_BINDER::getTextValue ( ) const
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().

◆ IsNull()

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.

◆ onKillFocus()

void MARGIN_OFFSET_BINDER::onKillFocus ( wxFocusEvent & aEvent)
protected

◆ onSetFocus()

void MARGIN_OFFSET_BINDER::onSetFocus ( wxFocusEvent & aEvent)
protected

Definition at line 206 of file margin_offset_binder.cpp.

References m_needsParsing.

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

◆ onUnitsChanged()

void MARGIN_OFFSET_BINDER::onUnitsChanged ( wxCommandEvent & aEvent)
protected

◆ parseInput()

bool MARGIN_OFFSET_BINDER::parseInput ( const wxString & aInput,
std::optional< int > & aOffset,
std::optional< double > & aRatio ) const
protected

Parse the input string and extract offset and ratio values.

Returns
true if parsing succeeded

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().

◆ SetOffsetValue()

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().

◆ SetRatioValue()

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().

◆ setTextValue()

void MARGIN_OFFSET_BINDER::setTextValue ( const wxString & aValue)
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().

◆ Show()

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.

Member Data Documentation

◆ m_cachedOffset

std::optional<int> MARGIN_OFFSET_BINDER::m_cachedOffset
mutableprotected

◆ m_cachedRatio

std::optional<double> MARGIN_OFFSET_BINDER::m_cachedRatio
mutableprotected

◆ m_eval

NUMERIC_EVALUATOR MARGIN_OFFSET_BINDER::m_eval
mutableprotected

Definition at line 141 of file margin_offset_binder.h.

Referenced by MARGIN_OFFSET_BINDER(), and onUnitsChanged().

◆ m_eventSource

wxWindow* MARGIN_OFFSET_BINDER::m_eventSource
protected

Definition at line 135 of file margin_offset_binder.h.

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

◆ m_iuScale

const EDA_IU_SCALE* MARGIN_OFFSET_BINDER::m_iuScale
protected

◆ m_label

wxStaticText* MARGIN_OFFSET_BINDER::m_label
protected

Definition at line 133 of file margin_offset_binder.h.

Referenced by Enable(), MARGIN_OFFSET_BINDER(), and Show().

◆ m_needsParsing

bool MARGIN_OFFSET_BINDER::m_needsParsing
mutableprotected

◆ m_unitLabel

wxStaticText* MARGIN_OFFSET_BINDER::m_unitLabel
protected

Can be nullptr.

Definition at line 136 of file margin_offset_binder.h.

Referenced by Enable(), MARGIN_OFFSET_BINDER(), and Show().

◆ m_units

EDA_UNITS MARGIN_OFFSET_BINDER::m_units
protected

◆ m_valueCtrl

wxWindow* MARGIN_OFFSET_BINDER::m_valueCtrl
protected

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