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...
 
 ~UNIT_BINDER () override
 
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...
 
void SetDataType (EDA_DATA_TYPE aDataType)
 Used to override the datatype of the displayed property (default is DISTANCE) 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 (const 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...
 
wxString GetOriginalText () const
 Function GetOriginalText Returns the pre-evaluated text (or the current text if evaluation is not supported). More...
 
virtual bool Validate (double aMin, double aMax, EDA_UNITS aUnits=EDA_UNITS::UNSCALED, bool aUseMils=false)
 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)
 
void onUnitsChanged (wxCommandEvent &aEvent)
 

Protected Attributes

EDA_DRAW_FRAMEm_frame
 
wxStaticText * m_label
 

The bound widgets

More...
 
wxWindow * m_value
 
wxStaticText * m_unitLabel
 
EDA_UNITS m_units
 

Currently used units.

More...
 
bool m_useMils
 
EDA_DATA_TYPE m_dataType
 
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 40 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 38 of file unit_binder.cpp.

40  :
41  m_frame( aParent ),
42  m_label( aLabel ),
43  m_value( aValue ),
44  m_unitLabel( aUnitLabel ),
45  m_eval( aParent->GetUserUnits(), aUseMils )
46 {
47  m_units = aParent->GetUserUnits();
48  m_useMils = aUseMils;
50  m_allowEval = allowEval && dynamic_cast<wxTextEntry*>( m_value );
51  m_needsEval = false;
52  m_selStart = 0;
53  m_selEnd = 0;
54 
55  wxTextEntry* textEntry = dynamic_cast<wxTextEntry*>( m_value );
56 
57  if( textEntry )
58  {
59  // Use ChangeValue() instead of SetValue() so we don't generate events.
60  textEntry->ChangeValue( wxT( "0" ) );
61  }
62 
64 
65  m_value->Connect( wxEVT_SET_FOCUS, wxFocusEventHandler( UNIT_BINDER::onSetFocus ), NULL, this );
66  m_value->Connect( wxEVT_KILL_FOCUS, wxFocusEventHandler( UNIT_BINDER::onKillFocus ), NULL, this );
67  Connect( DELAY_FOCUS, wxCommandEventHandler( UNIT_BINDER::delayedFocusHandler ), NULL, this );
68 
69  m_frame->Connect( UNITS_CHANGED, wxCommandEventHandler( UNIT_BINDER::onUnitsChanged ), nullptr, this );
70 }
EDA_DRAW_FRAME * m_frame
Definition: unit_binder.h:164
void delayedFocusHandler(wxCommandEvent &aEvent)
wxWindow * m_value
Definition: unit_binder.h:168
bool m_needsEval
Definition: unit_binder.h:182
wxString GetAbbreviatedUnitsLabel(EDA_UNITS aUnit, bool aUseMils, EDA_DATA_TYPE aType)
Get the units string for a given units type.
Definition: base_units.cpp:495
EDA_UNITS m_units
Currently used units.
Definition: unit_binder.h:172
#define NULL
wxStaticText * m_label
The bound widgets
Definition: unit_binder.h:167
EDA_DATA_TYPE m_dataType
Definition: unit_binder.h:174
wxStaticText * m_unitLabel
Definition: unit_binder.h:169
NUMERIC_EVALUATOR m_eval
Evaluator
Definition: unit_binder.h:180
bool m_useMils
Definition: unit_binder.h:173
bool m_allowEval
Definition: unit_binder.h:181
void onKillFocus(wxFocusEvent &aEvent)
void onSetFocus(wxFocusEvent &aEvent)
void onUnitsChanged(wxCommandEvent &aEvent)
Definition: unit_binder.cpp:94
long m_selStart
Selection start and end of the original text
Definition: unit_binder.h:185
EDA_UNITS GetUserUnits() const
Return the user units currently in use.

References delayedFocusHandler(), DISTANCE, GetAbbreviatedUnitsLabel(), EDA_BASE_FRAME::GetUserUnits(), m_allowEval, m_dataType, m_frame, m_needsEval, m_selEnd, m_selStart, m_unitLabel, m_units, m_useMils, m_value, NULL, onKillFocus(), onSetFocus(), and onUnitsChanged().

◆ ~UNIT_BINDER()

UNIT_BINDER::~UNIT_BINDER ( )
override

Definition at line 73 of file unit_binder.cpp.

74 {
75  m_frame->Disconnect( UNITS_CHANGED, wxCommandEventHandler( UNIT_BINDER::onUnitsChanged ), nullptr, this );
76 }
EDA_DRAW_FRAME * m_frame
Definition: unit_binder.h:164
void onUnitsChanged(wxCommandEvent &aEvent)
Definition: unit_binder.cpp:94

References m_frame, and onUnitsChanged().

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

252 {
253  ChangeValue( StringFromValue( m_units, aValue, false, m_useMils ) );
254 }
EDA_UNITS m_units
Currently used units.
Definition: unit_binder.h:172
bool m_useMils
Definition: unit_binder.h:173
wxString StringFromValue(EDA_UNITS aUnits, double aValue, bool aAddUnitSymbol, bool aUseMils, EDA_DATA_TYPE aType)
Function StringFromValue returns the string from aValue according to units (inch, mm ....
Definition: base_units.cpp:233
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(), DIALOG_TRACK_VIA_PROPERTIES::onViaSelect(), and DIALOG_PAD_PROPERTIES::updateRoundRectCornerValues().

◆ ChangeValue() [2/2]

void UNIT_BINDER::ChangeValue ( const wxString &  aValue)

Definition at line 257 of file unit_binder.cpp.

258 {
259  wxTextEntry* textEntry = dynamic_cast<wxTextEntry*>( m_value );
260  wxStaticText* staticText = dynamic_cast<wxStaticText*>( m_value );
261 
262  if( textEntry )
263  textEntry->ChangeValue( aValue );
264  else if( staticText )
265  staticText->SetLabel( aValue );
266 
267  if( m_allowEval )
268  m_eval.Clear();
269 
271 }
wxWindow * m_value
Definition: unit_binder.h:168
wxString GetAbbreviatedUnitsLabel(EDA_UNITS aUnit, bool aUseMils, EDA_DATA_TYPE aType)
Get the units string for a given units type.
Definition: base_units.cpp:495
EDA_UNITS m_units
Currently used units.
Definition: unit_binder.h:172
EDA_DATA_TYPE m_dataType
Definition: unit_binder.h:174
wxStaticText * m_unitLabel
Definition: unit_binder.h:169
NUMERIC_EVALUATOR m_eval
Evaluator
Definition: unit_binder.h:180
bool m_useMils
Definition: unit_binder.h:173
bool m_allowEval
Definition: unit_binder.h:181

References NUMERIC_EVALUATOR::Clear(), GetAbbreviatedUnitsLabel(), m_allowEval, m_dataType, m_eval, m_unitLabel, m_units, m_useMils, and m_value.

◆ delayedFocusHandler()

void UNIT_BINDER::delayedFocusHandler ( wxCommandEvent &  aEvent)
protected

Definition at line 169 of file unit_binder.cpp.

170 {
171  if( !m_errorMessage.IsEmpty() )
172  DisplayError( m_value->GetParent(), m_errorMessage );
173 
174  m_errorMessage = wxEmptyString;
175  m_value->SetFocus();
176 }
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:177
wxWindow * m_value
Definition: unit_binder.h:168

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

352 {
353  m_label->Enable( aEnable );
354  m_value->Enable( aEnable );
355  m_unitLabel->Enable( aEnable );
356 }
wxWindow * m_value
Definition: unit_binder.h:168
wxStaticText * m_label
The bound widgets
Definition: unit_binder.h:167
wxStaticText * m_unitLabel
Definition: unit_binder.h:169

References m_label, m_unitLabel, and m_value.

Referenced by 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 296 of file unit_binder.cpp.

297 {
298  wxTextEntry* textEntry = dynamic_cast<wxTextEntry*>( m_value );
299  wxStaticText* staticText = dynamic_cast<wxStaticText*>( m_value );
300  wxString value;
301 
302  if( textEntry )
303  {
304  if( m_needsEval && m_eval.Process( textEntry->GetValue() ) )
305  value = m_eval.Result();
306  else
307  value = textEntry->GetValue();
308  }
309  else if( staticText )
310  value = staticText->GetLabel();
311  else
312  return 0.0;
313 
315 }
wxWindow * m_value
Definition: unit_binder.h:168
double DoubleValueFromString(EDA_UNITS aUnits, const wxString &aTextValue, bool aUseMils, EDA_DATA_TYPE aType)
Function DoubleValueFromString converts aTextValue to a double.
Definition: base_units.cpp:346
bool m_needsEval
Definition: unit_binder.h:182
EDA_UNITS m_units
Currently used units.
Definition: unit_binder.h:172
bool Process(const wxString &aString)
EDA_DATA_TYPE m_dataType
Definition: unit_binder.h:174
NUMERIC_EVALUATOR m_eval
Evaluator
Definition: unit_binder.h:180
bool m_useMils
Definition: unit_binder.h:173
wxString Result() const

References DoubleValueFromString(), m_dataType, 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(), and DIALOG_MOVE_EXACT::OnTextChanged().

◆ GetOriginalText()

wxString UNIT_BINDER::GetOriginalText ( ) const

Function GetOriginalText Returns the pre-evaluated text (or the current text if evaluation is not supported).

Used primarily to remember values between dialog invocations.

Definition at line 329 of file unit_binder.cpp.

330 {
331  wxTextEntry* textEntry = dynamic_cast<wxTextEntry*>( m_value );
332  wxStaticText* staticText = dynamic_cast<wxStaticText*>( m_value );
333 
334  if( m_allowEval )
335  return m_eval.OriginalText();
336  else if( textEntry )
337  return textEntry->GetValue();
338  else if( staticText )
339  return staticText->GetLabel();
340  else
341  return wxEmptyString;
342 }
wxWindow * m_value
Definition: unit_binder.h:168
wxString OriginalText() const
NUMERIC_EVALUATOR m_eval
Evaluator
Definition: unit_binder.h:180
bool m_allowEval
Definition: unit_binder.h:181

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

Referenced by DIALOG_MOVE_EXACT::TransferDataFromWindow().

◆ GetValue()

long long int UNIT_BINDER::GetValue ( )
virtual

Function GetValue Returns the current value in Internal Units.

Definition at line 274 of file unit_binder.cpp.

275 {
276  wxTextEntry* textEntry = dynamic_cast<wxTextEntry*>( m_value );
277  wxStaticText* staticText = dynamic_cast<wxStaticText*>( m_value );
278  wxString value;
279 
280  if( textEntry )
281  {
282  if( m_needsEval && m_eval.Process( textEntry->GetValue() ) )
283  value = m_eval.Result();
284  else
285  value = textEntry->GetValue();
286  }
287  else if( staticText )
288  value = staticText->GetLabel();
289  else
290  return 0;
291 
292  return ValueFromString( m_units, value, m_useMils, m_dataType );
293 }
wxWindow * m_value
Definition: unit_binder.h:168
bool m_needsEval
Definition: unit_binder.h:182
EDA_UNITS m_units
Currently used units.
Definition: unit_binder.h:172
bool Process(const wxString &aString)
EDA_DATA_TYPE m_dataType
Definition: unit_binder.h:174
NUMERIC_EVALUATOR m_eval
Evaluator
Definition: unit_binder.h:180
bool m_useMils
Definition: unit_binder.h:173
wxString Result() const
long long int ValueFromString(EDA_UNITS aUnits, const wxString &aTextValue, bool aUseMils, EDA_DATA_TYPE aType)
Function ValueFromString converts aTextValue in aUnits to internal units used by the application.
Definition: base_units.cpp:471

References m_dataType, 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_PROPERTIES::onCornerRadiusChange(), DIALOG_PAD_PRIMITIVE_POLY_PROPS::onPaintPolyPanel(), DIALOG_LIB_EDIT_PIN::OnPropertiesChange(), onUnitsChanged(), DIALOG_PAD_PROPERTIES::PadTypeSelected(), DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS::processItem(), DIALOG_DRC::setDRCParameters(), DIALOG_PLOT_SCHEMATIC::SetHPGLPenWidth(), DIALOG_GRID_SETTINGS::TransferDataFromWindow(), DIALOG_JUNCTION_PROPS::TransferDataFromWindow(), PANEL_EESCHEMA_SETTINGS::TransferDataFromWindow(), 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_EDIT_SHEET_PIN::TransferDataFromWindow(), DIALOG_PNS_LENGTH_TUNING_SETTINGS::TransferDataFromWindow(), PANEL_LIBEDIT_SETTINGS::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(), DIALOG_CREATE_ARRAY::TransferDataFromWindow(), PANEL_SETUP_FEATURE_CONSTRAINTS::TransferDataFromWindow(), DIALOG_TEXT_PROPERTIES::TransferDataFromWindow(), DIALOG_EDIT_COMPONENT_IN_LIBRARY::TransferDataFromWindow(), DIALOG_GRAPHIC_ITEM_PROPERTIES::TransferDataFromWindow(), DIALOG_COPPER_ZONE::TransferDataFromWindow(), DIALOG_LABEL_EDITOR::TransferDataFromWindow(), DIALOG_FOOTPRINT_FP_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 318 of file unit_binder.cpp.

319 {
320  wxTextEntry* te = dynamic_cast<wxTextEntry*>( m_value );
321 
322  if( te )
323  return te->GetValue() == INDETERMINATE_STATE || te->GetValue() == INDETERMINATE_ACTION;
324 
325  return false;
326 }
#define INDETERMINATE_STATE
wxWindow * m_value
Definition: unit_binder.h:168
#define INDETERMINATE_ACTION

References INDETERMINATE_ACTION, INDETERMINATE_STATE, and m_value.

Referenced by DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS::processItem(), DIALOG_JUNCTION_PROPS::TransferDataFromWindow(), 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 127 of file unit_binder.cpp.

128 {
129  wxTextEntry* textEntry = dynamic_cast<wxTextEntry*>( m_value );
130 
131  if( m_allowEval && textEntry )
132  {
133  if( m_eval.Process( textEntry->GetValue() ) )
134  {
135  textEntry->GetSelection( &m_selStart, &m_selEnd );
136  wxString sel = textEntry->GetStringSelection();
137 
138  textEntry->ChangeValue( m_eval.Result() );
139 
140 #ifdef __WXGTK__
141  // Manually copy the selected text to the primary selection clipboard
142  if( wxTheClipboard->Open() )
143  {
144  bool clipTarget = wxTheClipboard->IsUsingPrimarySelection();
145  wxTheClipboard->UsePrimarySelection( true );
146  wxTheClipboard->SetData( new wxTextDataObject( sel ) );
147  wxTheClipboard->UsePrimarySelection( clipTarget );
148  wxTheClipboard->Close();
149  }
150 #endif
151  }
152 
153  m_needsEval = false;
154  }
155 
156  aEvent.Skip();
157 }
wxWindow * m_value
Definition: unit_binder.h:168
bool m_needsEval
Definition: unit_binder.h:182
bool Process(const wxString &aString)
NUMERIC_EVALUATOR m_eval
Evaluator
Definition: unit_binder.h:180
bool m_allowEval
Definition: unit_binder.h:181
wxString Result() const
long m_selStart
Selection start and end of the original text
Definition: unit_binder.h:185

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

107 {
108  wxTextEntry* textEntry = dynamic_cast<wxTextEntry*>( m_value );
109 
110  if( m_allowEval && textEntry )
111  {
112  wxString oldStr = m_eval.OriginalText();
113 
114  if( oldStr.length() )
115  {
116  textEntry->SetValue( oldStr );
117  textEntry->SetSelection( m_selStart, m_selEnd );
118  }
119 
120  m_needsEval = true;
121  }
122 
123  aEvent.Skip();
124 }
wxWindow * m_value
Definition: unit_binder.h:168
wxString OriginalText() const
bool m_needsEval
Definition: unit_binder.h:182
NUMERIC_EVALUATOR m_eval
Evaluator
Definition: unit_binder.h:180
bool m_allowEval
Definition: unit_binder.h:181
long m_selStart
Selection start and end of the original text
Definition: unit_binder.h:185

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

Referenced by UNIT_BINDER().

◆ onUnitsChanged()

void UNIT_BINDER::onUnitsChanged ( wxCommandEvent &  aEvent)
protected

Definition at line 94 of file unit_binder.cpp.

95 {
96  int temp = (int) GetValue();
97 
99 
100  SetValue( temp );
101 
102  aEvent.Skip();
103 }
EDA_DRAW_FRAME * m_frame
Definition: unit_binder.h:164
bool m_useMils
Definition: unit_binder.h:173
virtual void SetValue(int aValue)
Function SetValue Sets new value (in Internal Units) for the text field, taking care of units convers...
virtual long long int GetValue()
Function GetValue Returns the current value in Internal Units.
EDA_UNITS GetUserUnits() const
Return the user units currently in use.
virtual void SetUnits(EDA_UNITS aUnits, bool aUseMils=false)
Function SetUnits Normally not needed (as the UNIT_BINDER inherits from the parent frame),...
Definition: unit_binder.cpp:79

References EDA_BASE_FRAME::GetUserUnits(), GetValue(), m_frame, m_useMils, SetUnits(), and SetValue().

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

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

88 {
89  m_dataType = aDataType;
91 }
wxString GetAbbreviatedUnitsLabel(EDA_UNITS aUnit, bool aUseMils, EDA_DATA_TYPE aType)
Get the units string for a given units type.
Definition: base_units.cpp:495
EDA_UNITS m_units
Currently used units.
Definition: unit_binder.h:172
EDA_DATA_TYPE m_dataType
Definition: unit_binder.h:174
wxStaticText * m_unitLabel
Definition: unit_binder.h:169
bool m_useMils
Definition: unit_binder.h:173

References GetAbbreviatedUnitsLabel(), m_dataType, m_unitLabel, m_units, and m_useMils.

Referenced by DIALOG_COPPER_ZONE::TransferDataToWindow().

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

229 {
230  SetValue( StringFromValue( m_units, aValue, false, m_useMils, m_dataType ) );
231 }
EDA_UNITS m_units
Currently used units.
Definition: unit_binder.h:172
EDA_DATA_TYPE m_dataType
Definition: unit_binder.h:174
bool m_useMils
Definition: unit_binder.h:173
virtual void SetValue(int aValue)
Function SetValue Sets new value (in Internal Units) for the text field, taking care of units convers...
wxString StringFromValue(EDA_UNITS aUnits, double aValue, bool aAddUnitSymbol, bool aUseMils, EDA_DATA_TYPE aType)
Function StringFromValue returns the string from aValue according to units (inch, mm ....
Definition: base_units.cpp:233

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

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

◆ SetLabel()

void UNIT_BINDER::SetLabel ( const wxString &  aLabel)

Definition at line 345 of file unit_binder.cpp.

346 {
347  m_label->SetLabel( aLabel );
348 }
wxStaticText * m_label
The bound widgets
Definition: unit_binder.h:167

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

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.

Definition at line 79 of file unit_binder.cpp.

80 {
81  m_units = aUnits;
82  m_useMils = aUseMils;
84 }
wxString GetAbbreviatedUnitsLabel(EDA_UNITS aUnit, bool aUseMils, EDA_DATA_TYPE aType)
Get the units string for a given units type.
Definition: base_units.cpp:495
EDA_UNITS m_units
Currently used units.
Definition: unit_binder.h:172
EDA_DATA_TYPE m_dataType
Definition: unit_binder.h:174
wxStaticText * m_unitLabel
Definition: unit_binder.h:169
bool m_useMils
Definition: unit_binder.h:173

References GetAbbreviatedUnitsLabel(), m_dataType, m_unitLabel, m_units, and m_useMils.

Referenced by DIALOG_CREATE_ARRAY::DIALOG_CREATE_ARRAY(), DIALOG_GRAPHIC_ITEM_PROPERTIES::DIALOG_GRAPHIC_ITEM_PROPERTIES(), DIALOG_MOVE_EXACT::DIALOG_MOVE_EXACT(), DIALOG_PAD_PRIMITIVES_TRANSFORM::DIALOG_PAD_PRIMITIVES_TRANSFORM(), DIALOG_PNS_LENGTH_TUNING_SETTINGS::DIALOG_PNS_LENGTH_TUNING_SETTINGS(), onUnitsChanged(), PANEL_SETUP_FORMATTING::TransferDataToWindow(), DIALOG_NON_COPPER_ZONES_EDITOR::TransferDataToWindow(), DIALOG_COPPER_ZONE::TransferDataToWindow(), DIALOG_PAD_PRIMITIVES_PROPERTIES::TransferDataToWindow(), DIALOG_POSITION_RELATIVE::updateDialogControls(), and DIALOG_MOVE_EXACT::updateDialogControls().

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

223 {
224  SetValue( StringFromValue( m_units, aValue, false, m_useMils, m_dataType ) );
225 }
EDA_UNITS m_units
Currently used units.
Definition: unit_binder.h:172
EDA_DATA_TYPE m_dataType
Definition: unit_binder.h:174
bool m_useMils
Definition: unit_binder.h:173
virtual void SetValue(int aValue)
Function SetValue Sets new value (in Internal Units) for the text field, taking care of units convers...
wxString StringFromValue(EDA_UNITS aUnits, double aValue, bool aAddUnitSymbol, bool aUseMils, EDA_DATA_TYPE aType)
Function StringFromValue returns the string from aValue according to units (inch, mm ....
Definition: base_units.cpp:233

References m_dataType, 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(), PANEL_SETUP_FORMATTING::ImportSettingsFrom(), 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_PAD_PROPERTIES::OnOffsetCheckbox(), DIALOG_PAD_PROPERTIES::OnPadToDieCheckbox(), DIALOG_GRID_SETTINGS::OnResetGridOriginClick(), onUnitsChanged(), DIALOG_PAD_PROPERTIES::PadTypeSelected(), DIALOG_JUNCTION_PROPS::resetDefaults(), DIALOG_EDIT_LINE_STYLE::resetDefaults(), SetDoubleValue(), DIALOG_LIB_NEW_COMPONENT::SetPinTextPosition(), DIALOG_JUNCTION_PROPS::TransferDataToWindow(), DIALOG_GRID_SETTINGS::TransferDataToWindow(), PANEL_EESCHEMA_SETTINGS::TransferDataToWindow(), DIALOG_EDIT_LINE_STYLE::TransferDataToWindow(), DIALOG_TRACK_VIA_SIZE::TransferDataToWindow(), DIALOG_PNS_DIFF_PAIR_DIMENSIONS::TransferDataToWindow(), DIALOG_LIB_EDIT_DRAW_ITEM::TransferDataToWindow(), PANEL_SETUP_FORMATTING::TransferDataToWindow(), DIALOG_EDIT_SHEET_PIN::TransferDataToWindow(), DIALOG_PNS_LENGTH_TUNING_SETTINGS::TransferDataToWindow(), PANEL_LIBEDIT_SETTINGS::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_EDIT_ONE_FIELD::TransferDataToWindow(), DIALOG_SCH_SHEET_PROPS::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_LABEL_EDITOR::TransferDataToWindow(), DIALOG_FOOTPRINT_FP_EDITOR::TransferDataToWindow(), DIALOG_FOOTPRINT_BOARD_EDITOR::TransferDataToWindow(), DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS::TransferDataToWindow(), DIALOG_PAD_PRIMITIVES_PROPERTIES::TransferDataToWindow(), and DIALOG_PAD_PRIMITIVE_POLY_PROPS::TransferDataToWindow().

◆ SetValue() [2/2]

void UNIT_BINDER::SetValue ( wxString  aValue)

Definition at line 234 of file unit_binder.cpp.

235 {
236  wxTextEntry* textEntry = dynamic_cast<wxTextEntry*>( m_value );
237  wxStaticText* staticText = dynamic_cast<wxStaticText*>( m_value );
238 
239  if( textEntry )
240  textEntry->SetValue( aValue );
241  else if( staticText )
242  staticText->SetLabel( aValue );
243 
244  if( m_allowEval )
245  m_eval.Clear();
246 
248 }
wxWindow * m_value
Definition: unit_binder.h:168
wxString GetAbbreviatedUnitsLabel(EDA_UNITS aUnit, bool aUseMils, EDA_DATA_TYPE aType)
Get the units string for a given units type.
Definition: base_units.cpp:495
EDA_UNITS m_units
Currently used units.
Definition: unit_binder.h:172
EDA_DATA_TYPE m_dataType
Definition: unit_binder.h:174
wxStaticText * m_unitLabel
Definition: unit_binder.h:169
NUMERIC_EVALUATOR m_eval
Evaluator
Definition: unit_binder.h:180
bool m_useMils
Definition: unit_binder.h:173
bool m_allowEval
Definition: unit_binder.h:181

References NUMERIC_EVALUATOR::Clear(), GetAbbreviatedUnitsLabel(), m_allowEval, m_dataType, 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 359 of file unit_binder.cpp.

360 {
361  m_label->Show( aShow );
362  m_value->Show( aShow );
363  m_unitLabel->Show( aShow );
364 
365  if( aResize )
366  {
367  if( aShow )
368  {
369  m_label->SetSize( -1, -1 );
370  m_value->SetSize( -1, -1 );
371  m_unitLabel->SetSize( -1, -1 );
372  }
373  else
374  {
375  m_label->SetSize( 0, 0 );
376  m_value->SetSize( 0, 0 );
377  m_unitLabel->SetSize( 0, 0 );
378  }
379  }
380 }
wxWindow * m_value
Definition: unit_binder.h:168
wxStaticText * m_label
The bound widgets
Definition: unit_binder.h:167
wxStaticText * m_unitLabel
Definition: unit_binder.h:169

References m_label, m_unitLabel, and m_value.

Referenced by DIALOG_TEXT_PROPERTIES::DIALOG_TEXT_PROPERTIES(), DIALOG_PAD_PROPERTIES::OnUpdateUI(), DIALOG_GRAPHIC_ITEM_PROPERTIES::TransferDataToWindow(), and DIALOG_PAD_PRIMITIVES_PROPERTIES::TransferDataToWindow().

◆ Validate()

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

Function Validate Validates 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)
aUseMilsif aUnits is EDA_UNITS::INCHES, interpret as mils
Returns
false on error.

Definition at line 179 of file unit_binder.cpp.

180 {
181  wxTextEntry* textEntry = dynamic_cast<wxTextEntry*>( m_value );
182 
183  if( !textEntry
184  || textEntry->GetValue() == INDETERMINATE_ACTION
185  || textEntry->GetValue() == INDETERMINATE_STATE )
186  {
187  return true;
188  }
189 
190  // TODO: Validate() does not currently support m_dataType being anything other than DISTANCE
191 
192  if( GetValue() < From_User_Unit( aUnits, aMin, aUseMils ) )
193  {
194  m_errorMessage = wxString::Format( _( "%s must be at least %s." ),
196  StringFromValue( m_units, aMin, true ) );
197 
198  textEntry->SelectAll();
199  // Don't focus directly; we might be inside a KillFocus event handler
200  wxPostEvent( this, wxCommandEvent( DELAY_FOCUS ) );
201 
202  return false;
203  }
204 
205  if( GetValue() > From_User_Unit( aUnits, aMax, aUseMils ) )
206  {
207  m_errorMessage = wxString::Format( _( "%s must be less than %s." ),
209  StringFromValue( m_units, aMax, true ) );
210 
211  textEntry->SelectAll();
212  // Don't focus directly; we might be inside a KillFocus event handler
213  wxPostEvent( this, wxCommandEvent( DELAY_FOCUS ) );
214 
215  return false;
216  }
217 
218  return true;
219 }
wxString m_errorMessage
Validation support.
Definition: unit_binder.h:177
#define INDETERMINATE_STATE
wxWindow * m_value
Definition: unit_binder.h:168
double From_User_Unit(EDA_UNITS aUnits, double aValue, bool aUseMils)
Return in internal units the value "val" given in a real unit such as "in", "mm" or "deg".
Definition: base_units.cpp:321
wxString valueDescriptionFromLabel(wxStaticText *aLabel)
EDA_UNITS m_units
Currently used units.
Definition: unit_binder.h:172
wxStaticText * m_label
The bound widgets
Definition: unit_binder.h:167
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
#define INDETERMINATE_ACTION
virtual long long int GetValue()
Function GetValue Returns the current value in Internal Units.
wxString StringFromValue(EDA_UNITS aUnits, double aValue, bool aAddUnitSymbol, bool aUseMils, EDA_DATA_TYPE aType)
Function StringFromValue returns the string from aValue according to units (inch, mm ....
Definition: base_units.cpp:233

References _, Format(), From_User_Unit(), GetValue(), INDETERMINATE_ACTION, INDETERMINATE_STATE, 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_GRID_SETTINGS::TransferDataFromWindow(), DIALOG_TRACK_VIA_PROPERTIES::TransferDataFromWindow(), DIALOG_TARGET_PROPERTIES::TransferDataFromWindow(), DIALOG_NON_COPPER_ZONES_EDITOR::TransferDataFromWindow(), PANEL_SETUP_FEATURE_CONSTRAINTS::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

◆ m_dataType

EDA_DATA_TYPE UNIT_BINDER::m_dataType
protected

◆ m_errorMessage

wxString UNIT_BINDER::m_errorMessage
protected

Validation support.

Definition at line 177 of file unit_binder.h.

Referenced by delayedFocusHandler(), and Validate().

◆ m_eval

NUMERIC_EVALUATOR UNIT_BINDER::m_eval
protected

Evaluator

Definition at line 180 of file unit_binder.h.

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

◆ m_frame

EDA_DRAW_FRAME* UNIT_BINDER::m_frame
protected

Definition at line 164 of file unit_binder.h.

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

◆ m_label

wxStaticText* UNIT_BINDER::m_label
protected

The bound widgets

Definition at line 167 of file unit_binder.h.

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

◆ m_needsEval

bool UNIT_BINDER::m_needsEval
protected

Definition at line 182 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 186 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 185 of file unit_binder.h.

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

◆ m_unitLabel

wxStaticText* UNIT_BINDER::m_unitLabel
protected

Definition at line 169 of file unit_binder.h.

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

◆ m_units

EDA_UNITS UNIT_BINDER::m_units
protected

Currently used units.

Definition at line 172 of file unit_binder.h.

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

◆ m_useMils

bool UNIT_BINDER::m_useMils
protected

◆ m_value


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