KiCad PCB EDA Suite
WX_UNIT_TEXT Class Reference

#include <wxunittext.h>

Inheritance diagram for WX_UNIT_TEXT:

Public Member Functions

 WX_UNIT_TEXT (wxWindow *aParent, const wxString &aLabel=_("Size:"), double aValue=0.0, double aStep=0.1)
 Constructor. More...
 
virtual ~WX_UNIT_TEXT ()
 
void SetUnits (EDA_UNITS_T aUnits, bool aConvert=false)
 Function SetUnits Changes the units used by the control. More...
 
virtual void SetValue (double aValue)
 Function SetValue Sets new value for the control. More...
 
virtual boost::optional< double > GetValue () const
 Function GetValue Returns the current value in currently used units. More...
 
EDA_UNITS_T GetUnits () const
 Function GetUnits Returns currently used units. More...
 
void SetStep (double aStep)
 Function SetStep Sets the difference introduced by a single spin button click. More...
 
double GetStep () const
 Function GetStep Returns the difference introduced by a single spin button click. More...
 

Protected Member Functions

void onSpinUpEvent (wxSpinEvent &aEvent)
 

Spin up button click event handler.

More...
 
void onSpinDownEvent (wxSpinEvent &aEvent)
 

Spin down button click event handler.

More...
 

Protected Attributes

wxStaticText * m_inputLabel
 

Label for the input (e.g. "Size:")

More...
 
wxTextCtrl * m_inputValue
 

Text input control.

More...
 
wxSpinButton * m_spinButton
 

Spin buttons for changing the value using mouse.

More...
 
wxStaticText * m_unitLabel
 

Label showing currently used units.

More...
 
EDA_UNITS_T m_units
 

Currently used units.

More...
 
double m_step
 

Step size (added/subtracted difference if spin buttons are used).

More...
 

Static Protected Attributes

static const wxString DEFAULT_VALUE = _( "default ")
 

Default value (or non-specified)

More...
 

Detailed Description

Definition at line 40 of file wxunittext.h.

Constructor & Destructor Documentation

WX_UNIT_TEXT::WX_UNIT_TEXT ( wxWindow *  aParent,
const wxString &  aLabel = _( "Size:" ),
double  aValue = 0.0,
double  aStep = 0.1 
)

Constructor.

Parameters
aParentis the parent window.
aLabelis the label displayed next to the text input control.
aValueis the initial value for the control.
aStepis the step size when using spin buttons.

Definition at line 34 of file wxunittext.cpp.

References g_UserUnit, GetUnitsLabel(), m_inputLabel, m_inputValue, m_spinButton, m_unitLabel, m_units, max, min, onSpinDownEvent(), onSpinUpEvent(), and SetValue().

34  :
35  wxPanel( aParent, wxID_ANY ),
36  m_step( aStep )
37 {
38  // Use the currently selected units
40 
41  wxBoxSizer* sizer;
42  sizer = new wxBoxSizer( wxHORIZONTAL );
43 
44  // Helper label
45  m_inputLabel = new wxStaticText( this, wxID_ANY, aLabel,
46  wxDefaultPosition, wxDefaultSize, 0 );
47  wxSize size = m_inputLabel->GetMinSize();
48  size.SetWidth( 150 );
49  m_inputLabel->SetMinSize( size );
50  sizer->Add( m_inputLabel, 1, wxALIGN_CENTER_VERTICAL | wxALL | wxEXPAND, 5 );
51 
52  // Main input control
53  m_inputValue = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize,
54  wxTE_PROCESS_ENTER );
55 
56  SetValue( aValue );
57  sizer->Add( m_inputValue, 0, wxALIGN_CENTER_VERTICAL | wxALL );
58 
59  wxFloatingPointValidator<double> validator( 4, NULL, wxNUM_VAL_NO_TRAILING_ZEROES );
60  validator.SetRange( 0.0, std::numeric_limits<double>::max() );
61  m_inputValue->SetValidator( validator );
62 
63  // Spin buttons for modifying values using the mouse
64  m_spinButton = new wxSpinButton( this, wxID_ANY );
66 
67  m_spinButton->SetCanFocus( false );
68  sizer->Add( m_spinButton, 0, wxALIGN_CENTER_VERTICAL | wxALL );
69 
70  Connect( wxEVT_SPIN_UP, wxSpinEventHandler( WX_UNIT_TEXT::onSpinUpEvent ), NULL, this );
71  Connect( wxEVT_SPIN_DOWN, wxSpinEventHandler( WX_UNIT_TEXT::onSpinDownEvent ), NULL, this );
72 
73  sizer->AddSpacer( 5 );
74 
75  // Create units label
76  m_unitLabel = new wxStaticText( this, wxID_ANY, GetUnitsLabel( g_UserUnit ),
77  wxDefaultPosition, wxDefaultSize, 0 );
78  sizer->Add( m_unitLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL );
79 
80  SetSizer( sizer );
81  Layout();
82 }
wxString GetUnitsLabel(EDA_UNITS_T aUnit)
Get a human readable units string.
Definition: base_units.cpp:452
virtual void SetValue(double aValue)
Function SetValue Sets new value for the control.
Definition: wxunittext.cpp:98
void onSpinUpEvent(wxSpinEvent &aEvent)
Spin up button click event handler.
Definition: wxunittext.cpp:127
wxTextCtrl * m_inputValue
Text input control.
Definition: wxunittext.h:126
wxStaticText * m_unitLabel
Label showing currently used units.
Definition: wxunittext.h:132
void onSpinDownEvent(wxSpinEvent &aEvent)
Spin down button click event handler.
Definition: wxunittext.cpp:133
EDA_UNITS_T g_UserUnit
Global variables definitions.
Definition: common.cpp:56
wxSpinButton * m_spinButton
Spin buttons for changing the value using mouse.
Definition: wxunittext.h:129
#define max(a, b)
Definition: auxiliary.h:86
double m_step
Step size (added/subtracted difference if spin buttons are used).
Definition: wxunittext.h:138
wxStaticText * m_inputLabel
Label for the input (e.g. "Size:")
Definition: wxunittext.h:123
EDA_UNITS_T m_units
Currently used units.
Definition: wxunittext.h:135
#define min(a, b)
Definition: auxiliary.h:85
WX_UNIT_TEXT::~WX_UNIT_TEXT ( )
virtual

Definition at line 85 of file wxunittext.cpp.

86 {
87 }

Member Function Documentation

double WX_UNIT_TEXT::GetStep ( ) const
inline

Function GetStep Returns the difference introduced by a single spin button click.

Definition at line 110 of file wxunittext.h.

References m_step.

111  {
112  return m_step;
113  }
double m_step
Step size (added/subtracted difference if spin buttons are used).
Definition: wxunittext.h:138
EDA_UNITS_T WX_UNIT_TEXT::GetUnits ( ) const
inline

Function GetUnits Returns currently used units.

Definition at line 89 of file wxunittext.h.

References m_units.

90  {
91  return m_units;
92  }
EDA_UNITS_T m_units
Currently used units.
Definition: wxunittext.h:135
boost::optional< double > WX_UNIT_TEXT::GetValue ( ) const
virtual

Function GetValue Returns the current value in currently used units.

Definition at line 112 of file wxunittext.cpp.

References DEFAULT_VALUE, and m_inputValue.

Referenced by onSpinDownEvent(), and onSpinUpEvent().

113 {
114  wxString text = m_inputValue->GetValue();
115  double value;
116 
117  if( text == DEFAULT_VALUE )
118  return boost::optional<double>( -1.0 );
119 
120  if( !text.ToDouble( &value ) )
121  return boost::optional<double>();
122 
123  return boost::optional<double>( value );
124 }
static const wxString DEFAULT_VALUE
Default value (or non-specified)
Definition: wxunittext.h:141
wxTextCtrl * m_inputValue
Text input control.
Definition: wxunittext.h:126
void WX_UNIT_TEXT::onSpinDownEvent ( wxSpinEvent &  aEvent)
protected

Spin down button click event handler.

Definition at line 133 of file wxunittext.cpp.

References GetValue(), m_step, and SetValue().

Referenced by WX_UNIT_TEXT().

134 {
135  double newValue = *GetValue() - m_step;
136 
137  if( newValue >= 0.0 )
138  SetValue( newValue );
139 }
virtual void SetValue(double aValue)
Function SetValue Sets new value for the control.
Definition: wxunittext.cpp:98
double m_step
Step size (added/subtracted difference if spin buttons are used).
Definition: wxunittext.h:138
virtual boost::optional< double > GetValue() const
Function GetValue Returns the current value in currently used units.
Definition: wxunittext.cpp:112
void WX_UNIT_TEXT::onSpinUpEvent ( wxSpinEvent &  aEvent)
protected

Spin up button click event handler.

Definition at line 127 of file wxunittext.cpp.

References GetValue(), m_step, and SetValue().

Referenced by WX_UNIT_TEXT().

128 {
129  SetValue( *GetValue() + m_step );
130 }
virtual void SetValue(double aValue)
Function SetValue Sets new value for the control.
Definition: wxunittext.cpp:98
double m_step
Step size (added/subtracted difference if spin buttons are used).
Definition: wxunittext.h:138
virtual boost::optional< double > GetValue() const
Function GetValue Returns the current value in currently used units.
Definition: wxunittext.cpp:112
void WX_UNIT_TEXT::SetStep ( double  aStep)
inline

Function SetStep Sets the difference introduced by a single spin button click.

Parameters
aStepis new step size.

Definition at line 99 of file wxunittext.h.

References m_step.

100  {
101  assert( aStep > 0.0 );
102 
103  m_step = aStep;
104  }
double m_step
Step size (added/subtracted difference if spin buttons are used).
Definition: wxunittext.h:138
void WX_UNIT_TEXT::SetUnits ( EDA_UNITS_T  aUnits,
bool  aConvert = false 
)

Function SetUnits Changes the units used by the control.

Parameters
aUnitsis the new unit to be used.
aConvertdecides if the current value should be converted to the value in new units or should it stay the same.

Definition at line 90 of file wxunittext.cpp.

References g_UserUnit, GetUnitsLabel(), and m_unitLabel.

91 {
92  assert( !aConvert ); // TODO conversion does not work yet
93 
94  m_unitLabel->SetLabel( GetUnitsLabel( g_UserUnit ) );
95 }
wxString GetUnitsLabel(EDA_UNITS_T aUnit)
Get a human readable units string.
Definition: base_units.cpp:452
wxStaticText * m_unitLabel
Label showing currently used units.
Definition: wxunittext.h:132
EDA_UNITS_T g_UserUnit
Global variables definitions.
Definition: common.cpp:56
void WX_UNIT_TEXT::SetValue ( double  aValue)
virtual

Function SetValue Sets new value for the control.

Parameters
aValueis the new value.

Definition at line 98 of file wxunittext.cpp.

References DEFAULT_VALUE, Double2Str(), and m_inputValue.

Referenced by onSpinDownEvent(), onSpinUpEvent(), and WX_UNIT_TEXT().

99 {
100  if( aValue >= 0.0 )
101  {
102  m_inputValue->SetValue( wxString( Double2Str( aValue ).c_str(), wxConvUTF8 ) );
103  m_inputValue->MarkDirty();
104  }
105  else
106  {
107  m_inputValue->SetValue( DEFAULT_VALUE );
108  }
109 }
static const wxString DEFAULT_VALUE
Default value (or non-specified)
Definition: wxunittext.h:141
std::string Double2Str(double aValue)
Helper function Double2Str to print a float number without using scientific notation and no trailing ...
Definition: base_units.cpp:60
wxTextCtrl * m_inputValue
Text input control.
Definition: wxunittext.h:126

Member Data Documentation

const wxString WX_UNIT_TEXT::DEFAULT_VALUE = _( "default ")
staticprotected

Default value (or non-specified)

Definition at line 141 of file wxunittext.h.

Referenced by GetValue(), and SetValue().

wxStaticText* WX_UNIT_TEXT::m_inputLabel
protected

Label for the input (e.g. "Size:")

Definition at line 123 of file wxunittext.h.

Referenced by WX_UNIT_TEXT().

wxTextCtrl* WX_UNIT_TEXT::m_inputValue
protected

Text input control.

Definition at line 126 of file wxunittext.h.

Referenced by GetValue(), SetValue(), and WX_UNIT_TEXT().

wxSpinButton* WX_UNIT_TEXT::m_spinButton
protected

Spin buttons for changing the value using mouse.

Definition at line 129 of file wxunittext.h.

Referenced by WX_UNIT_TEXT().

double WX_UNIT_TEXT::m_step
protected

Step size (added/subtracted difference if spin buttons are used).

Definition at line 138 of file wxunittext.h.

Referenced by GetStep(), onSpinDownEvent(), onSpinUpEvent(), and SetStep().

wxStaticText* WX_UNIT_TEXT::m_unitLabel
protected

Label showing currently used units.

Definition at line 132 of file wxunittext.h.

Referenced by SetUnits(), and WX_UNIT_TEXT().

EDA_UNITS_T WX_UNIT_TEXT::m_units
protected

Currently used units.

Definition at line 135 of file wxunittext.h.

Referenced by GetUnits(), and WX_UNIT_TEXT().


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