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 *aValueCtrl, wxStaticText *aUnitLabel, bool aAllowEval=true)
 
 ~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. More...
 
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. More...
 
void SetDataType (EDA_DATA_TYPE aDataType)
 Used to override the datatype of the displayed property (default is DISTANCE) More...
 
virtual void SetValue (long long int aValue)
 Set new value (in Internal Units) for the text field, taking care of units conversion. More...
 
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. More...
 
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. More...
 
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. More...
 
virtual long long int GetValue ()
 Return the current value in Internal Units. More...
 
virtual double GetDoubleValue ()
 Return the current value in Internal Units. More...
 
bool IsIndeterminate () const
 Return true if the control holds the indeterminate value (for instance, if it represents a multiple selection of differing values). More...
 
wxString GetOriginalText () const
 Return 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)
 Validate the control against the given range, informing the user of any errors found. More...
 
void SetLabel (const wxString &aLabel)
 
void Enable (bool aEnable)
 Enable/disable the label, widget and units label. More...
 
void Show (bool aShow, bool aResize=false)
 Show/hide the label, widget and units label. More...
 
ORIGIN_TRANSFORMS::COORD_TYPES_T GetCoordType () const
 Get the origin transforms coordinate type. More...
 
void SetCoordType (ORIGIN_TRANSFORMS::COORD_TYPES_T aCoordType)
 Set the current origin transform mode. More...
 
void RequireEval ()
 Force the binder to evaluate the text. More...
 

Protected Member Functions

void onSetFocus (wxFocusEvent &aEvent)
 
void onKillFocus (wxFocusEvent &aEvent)
 
void delayedFocusHandler (wxCommandEvent &aEvent)
 
void onUnitsChanged (wxCommandEvent &aEvent)
 
double setPrecision (double aValue, bool aValueUsesUserUnits)
 When m_precision > 0 truncate the value aValue to show only m_precision digits in mantissa. More...
 

Protected Attributes

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

Detailed Description

Definition at line 41 of file unit_binder.h.

Constructor & Destructor Documentation

◆ UNIT_BINDER()

UNIT_BINDER::UNIT_BINDER ( EDA_DRAW_FRAME aParent,
wxStaticText *  aLabel,
wxWindow *  aValueCtrl,
wxStaticText *  aUnitLabel,
bool  aAllowEval = true 
)
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)
aValueCtrlis the control used to edit or display the given value (wxTextCtrl, wxComboBox, wxStaticText, etc.).
aUnitLabelis the units label displayed after the text input widget Can be nullptr.
aAllowEvalindicates aTextInput's content should be eval'ed before storing

Definition at line 40 of file unit_binder.cpp.

41  :
42  m_frame( aParent ),
43  m_label( aLabel ),
44  m_valueCtrl( aValueCtrl ),
45  m_unitLabel( aUnitLabel ),
46  m_negativeZero( false ),
48  m_precision( 0 ),
49  m_eval( aParent->GetUserUnits() ),
52 {
53  m_units = aParent->GetUserUnits();
54  m_allowEval = allowEval && dynamic_cast<wxTextEntry*>( m_valueCtrl );
55  m_needsEval = false;
56  m_selStart = 0;
57  m_selEnd = 0;
58 
59  wxTextEntry* textEntry = dynamic_cast<wxTextEntry*>( m_valueCtrl );
60 
61  if( textEntry )
62  {
63  // Use ChangeValue() instead of SetValue() so we don't generate events.
64  if( m_negativeZero )
65  textEntry->ChangeValue( wxT( "-0" ) );
66  else
67  textEntry->ChangeValue( wxT( "0" ) );
68  }
69 
70  if( m_unitLabel )
72 
73  m_valueCtrl->Connect( wxEVT_SET_FOCUS, wxFocusEventHandler( UNIT_BINDER::onSetFocus ),
74  nullptr, this );
75  m_valueCtrl->Connect( wxEVT_KILL_FOCUS, wxFocusEventHandler( UNIT_BINDER::onKillFocus ),
76  nullptr, this );
77  Connect( DELAY_FOCUS, wxCommandEventHandler( UNIT_BINDER::delayedFocusHandler ), nullptr,
78  this );
79 
80  m_frame->Connect( UNITS_CHANGED, wxCommandEventHandler( UNIT_BINDER::onUnitsChanged ),
81  nullptr, this );
82 }
ORIGIN_TRANSFORMS::COORD_TYPES_T m_coordType
Type of coordinate for display origin transforms.
Definition: unit_binder.h:237
EDA_DRAW_FRAME * m_frame
The bound widgets.
Definition: unit_binder.h:211
void delayedFocusHandler(wxCommandEvent &aEvent)
ORIGIN_TRANSFORMS & m_originTransforms
A reference to an ORIGIN_TRANSFORMS object.
Definition: unit_binder.h:234
virtual ORIGIN_TRANSFORMS & GetOriginTransforms()
Return a reference to the default ORIGIN_TRANSFORMS object.
bool m_needsEval
Definition: unit_binder.h:228
wxString GetAbbreviatedUnitsLabel(EDA_UNITS aUnit, EDA_DATA_TYPE aType)
Get the units string for a given units type.
Definition: base_units.cpp:419
EDA_UNITS m_units
Definition: unit_binder.h:219
wxStaticText * m_label
Definition: unit_binder.h:214
EDA_DATA_TYPE m_dataType
Definition: unit_binder.h:221
wxStaticText * m_unitLabel
Can be nullptr.
Definition: unit_binder.h:216
NUMERIC_EVALUATOR m_eval
Definition: unit_binder.h:226
wxWindow * m_valueCtrl
Definition: unit_binder.h:215
bool m_negativeZero
Indicates "-0" should be displayed for 0.
Definition: unit_binder.h:220
int m_precision
0 to 6
Definition: unit_binder.h:222
bool m_allowEval
Definition: unit_binder.h:227
void onKillFocus(wxFocusEvent &aEvent)
void onSetFocus(wxFocusEvent &aEvent)
void onUnitsChanged(wxCommandEvent &aEvent)
long m_selStart
Selection start and end of the original text.
Definition: unit_binder.h:230
EDA_UNITS GetUserUnits() const
Return the user units currently in use.

References delayedFocusHandler(), GetAbbreviatedUnitsLabel(), EDA_BASE_FRAME::GetUserUnits(), m_allowEval, m_dataType, m_frame, m_needsEval, m_negativeZero, m_selEnd, m_selStart, m_unitLabel, m_units, m_valueCtrl, onKillFocus(), onSetFocus(), and onUnitsChanged().

◆ ~UNIT_BINDER()

UNIT_BINDER::~UNIT_BINDER ( )
override

Definition at line 85 of file unit_binder.cpp.

86 {
87  m_frame->Disconnect( UNITS_CHANGED, wxCommandEventHandler( UNIT_BINDER::onUnitsChanged ),
88  nullptr, this );
89 }
EDA_DRAW_FRAME * m_frame
The bound widgets.
Definition: unit_binder.h:211
void onUnitsChanged(wxCommandEvent &aEvent)

References m_frame, and onUnitsChanged().

Member Function Documentation

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

308 {
309  double displayValue = m_originTransforms.ToDisplay( aValue, m_coordType );
310  displayValue = setPrecision( displayValue, false );
311 
312  if( displayValue == 0 && m_negativeZero )
313  ChangeValue( wxT( "-" ) + StringFromValue( m_units, displayValue, false, m_dataType ) );
314  else
315  ChangeValue( StringFromValue( m_units, displayValue, false, m_dataType ) );
316 }
ORIGIN_TRANSFORMS::COORD_TYPES_T m_coordType
Type of coordinate for display origin transforms.
Definition: unit_binder.h:237
ORIGIN_TRANSFORMS & m_originTransforms
A reference to an ORIGIN_TRANSFORMS object.
Definition: unit_binder.h:234
EDA_UNITS m_units
Definition: unit_binder.h:219
EDA_DATA_TYPE m_dataType
Definition: unit_binder.h:221
bool m_negativeZero
Indicates "-0" should be displayed for 0.
Definition: unit_binder.h:220
virtual int ToDisplay(int aValue, COORD_TYPES_T aCoordType) const
wxString StringFromValue(EDA_UNITS aUnits, double aValue, bool aAddUnitSymbol, EDA_DATA_TYPE aType)
Convert a value to a string using double notation.
Definition: base_units.cpp:204
double setPrecision(double aValue, bool aValueUsesUserUnits)
When m_precision > 0 truncate the value aValue to show only m_precision digits in mantissa.
virtual void ChangeValue(int aValue)
Set new value (in Internal Units) for the text field, taking care of units conversion WITHOUT trigger...

References ChangeValue(), m_coordType, m_dataType, m_negativeZero, m_originTransforms, m_units, setPrecision(), StringFromValue(), and ORIGIN_TRANSFORMS::ToDisplay().

Referenced by DIALOG_PAD_PROPERTIES::initValues(), DIALOG_PAD_PROPERTIES::onCornerRadiusChange(), DIALOG_PAD_PROPERTIES::OnPadShapeSelection(), and DIALOG_PAD_PROPERTIES::updateRoundRectCornerValues().

◆ ChangeValue() [1/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 295 of file unit_binder.cpp.

296 {
297  double value = aValue;
298  double displayValue = m_originTransforms.ToDisplay( value, m_coordType );
299 
300  if( displayValue == 0 && m_negativeZero )
301  ChangeValue( wxT( "-" ) + StringFromValue( m_units, displayValue, false ) );
302  else
303  ChangeValue( StringFromValue( m_units, displayValue, false ) );
304 }
ORIGIN_TRANSFORMS::COORD_TYPES_T m_coordType
Type of coordinate for display origin transforms.
Definition: unit_binder.h:237
ORIGIN_TRANSFORMS & m_originTransforms
A reference to an ORIGIN_TRANSFORMS object.
Definition: unit_binder.h:234
EDA_UNITS m_units
Definition: unit_binder.h:219
bool m_negativeZero
Indicates "-0" should be displayed for 0.
Definition: unit_binder.h:220
virtual int ToDisplay(int aValue, COORD_TYPES_T aCoordType) const
wxString StringFromValue(EDA_UNITS aUnits, double aValue, bool aAddUnitSymbol, EDA_DATA_TYPE aType)
Convert a value to a string using double notation.
Definition: base_units.cpp:204
virtual void ChangeValue(int aValue)
Set new value (in Internal Units) for the text field, taking care of units conversion WITHOUT trigger...

References m_coordType, m_negativeZero, m_originTransforms, m_units, StringFromValue(), and ORIGIN_TRANSFORMS::ToDisplay().

Referenced by ChangeDoubleValue(), DIALOG_PAD_PROPERTIES::initValues(), DIALOG_PAD_PROPERTIES::onCornerSizePercentChange(), DIALOG_PAD_PROPERTIES::OnPadShapeSelection(), DIALOG_TRACK_VIA_PROPERTIES::onViaSelect(), DIALOG_PAD_PROPERTIES::PadTypeSelected(), DIALOG_LIB_SYMBOL_PROPERTIES::TransferDataToWindow(), and DIALOG_PAD_PROPERTIES::updateRoundRectCornerValues().

◆ ChangeValue() [2/2]

void UNIT_BINDER::ChangeValue ( const wxString &  aValue)

Definition at line 319 of file unit_binder.cpp.

320 {
321  wxTextEntry* textEntry = dynamic_cast<wxTextEntry*>( m_valueCtrl );
322  wxStaticText* staticText = dynamic_cast<wxStaticText*>( m_valueCtrl );
323 
324  if( textEntry )
325  textEntry->ChangeValue( aValue );
326  else if( staticText )
327  staticText->SetLabel( aValue );
328 
329  if( m_allowEval )
330  m_eval.Clear();
331 
332  if( m_unitLabel )
334 }
wxString GetAbbreviatedUnitsLabel(EDA_UNITS aUnit, EDA_DATA_TYPE aType)
Get the units string for a given units type.
Definition: base_units.cpp:419
EDA_UNITS m_units
Definition: unit_binder.h:219
EDA_DATA_TYPE m_dataType
Definition: unit_binder.h:221
wxStaticText * m_unitLabel
Can be nullptr.
Definition: unit_binder.h:216
NUMERIC_EVALUATOR m_eval
Definition: unit_binder.h:226
wxWindow * m_valueCtrl
Definition: unit_binder.h:215
bool m_allowEval
Definition: unit_binder.h:227

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

◆ delayedFocusHandler()

void UNIT_BINDER::delayedFocusHandler ( wxCommandEvent &  aEvent)
protected

Definition at line 196 of file unit_binder.cpp.

197 {
198  if( !m_errorMessage.IsEmpty() )
199  DisplayError( m_valueCtrl->GetParent(), m_errorMessage );
200 
201  m_errorMessage = wxEmptyString;
202  m_valueCtrl->SetFocus();
203 }
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:279
wxString m_errorMessage
Definition: unit_binder.h:224
wxWindow * m_valueCtrl
Definition: unit_binder.h:215

References DisplayError(), m_errorMessage, and m_valueCtrl.

Referenced by UNIT_BINDER().

◆ Enable()

◆ 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 169 of file unit_binder.h.

170  {
171  return m_coordType;
172  }
ORIGIN_TRANSFORMS::COORD_TYPES_T m_coordType
Type of coordinate for display origin transforms.
Definition: unit_binder.h:237

References m_coordType.

◆ GetDoubleValue()

double UNIT_BINDER::GetDoubleValue ( )
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 380 of file unit_binder.cpp.

381 {
382  wxTextEntry* textEntry = dynamic_cast<wxTextEntry*>( m_valueCtrl );
383  wxStaticText* staticText = dynamic_cast<wxStaticText*>( m_valueCtrl );
384  wxString value;
385 
386  if( textEntry )
387  {
388  if( m_needsEval && m_eval.Process( textEntry->GetValue() ) )
389  value = m_eval.Result();
390  else
391  value = textEntry->GetValue();
392  }
393  else if( staticText )
394  {
395  value = staticText->GetLabel();
396  }
397  else
398  {
399  return 0.0;
400  }
401 
402  double displayValue = DoubleValueFromString( m_units, value, m_dataType );
403  displayValue = setPrecision( displayValue, false );
404 
405  return m_originTransforms.FromDisplay( displayValue, m_coordType );
406 }
ORIGIN_TRANSFORMS::COORD_TYPES_T m_coordType
Type of coordinate for display origin transforms.
Definition: unit_binder.h:237
ORIGIN_TRANSFORMS & m_originTransforms
A reference to an ORIGIN_TRANSFORMS object.
Definition: unit_binder.h:234
bool m_needsEval
Definition: unit_binder.h:228
EDA_UNITS m_units
Definition: unit_binder.h:219
bool Process(const wxString &aString)
EDA_DATA_TYPE m_dataType
Definition: unit_binder.h:221
NUMERIC_EVALUATOR m_eval
Definition: unit_binder.h:226
wxWindow * m_valueCtrl
Definition: unit_binder.h:215
wxString Result() const
virtual int FromDisplay(int aValue, COORD_TYPES_T aCoordType) const
double setPrecision(double aValue, bool aValueUsesUserUnits)
When m_precision > 0 truncate the value aValue to show only m_precision digits in mantissa.
double DoubleValueFromString(EDA_UNITS aUnits, const wxString &aTextValue, EDA_DATA_TYPE aType)
Function DoubleValueFromString converts aTextValue to a double.
Definition: base_units.cpp:302

References DoubleValueFromString(), ORIGIN_TRANSFORMS::FromDisplay(), m_coordType, m_dataType, m_eval, m_needsEval, m_originTransforms, m_units, m_valueCtrl, NUMERIC_EVALUATOR::Process(), NUMERIC_EVALUATOR::Result(), and setPrecision().

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(), DIALOG_MOVE_EXACT::OnTextChanged(), DIALOG_PAD_PROPERTIES::padValuesOK(), PANEL_SETUP_MASK_AND_PASTE::TransferDataFromWindow(), DIALOG_TEXT_PROPERTIES::TransferDataFromWindow(), DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::TransferDataFromWindow(), DIALOG_FOOTPRINT_PROPERTIES::TransferDataFromWindow(), DIALOG_MOVE_EXACT::TransferDataFromWindow(), DIALOG_PAD_PROPERTIES::transferDataToPad(), and DIALOG_GRAPHIC_ITEM_PROPERTIES::Validate().

◆ GetOriginalText()

wxString UNIT_BINDER::GetOriginalText ( ) const

Return the pre-evaluated text (or the current text if evaluation is not supported).

Used primarily to remember values between dialog invocations.

Definition at line 420 of file unit_binder.cpp.

421 {
422  wxTextEntry* textEntry = dynamic_cast<wxTextEntry*>( m_valueCtrl );
423  wxStaticText* staticText = dynamic_cast<wxStaticText*>( m_valueCtrl );
424 
425  if( m_allowEval )
426  return m_eval.OriginalText();
427  else if( textEntry )
428  return textEntry->GetValue();
429  else if( staticText )
430  return staticText->GetLabel();
431  else
432  return wxEmptyString;
433 }
wxString OriginalText() const
NUMERIC_EVALUATOR m_eval
Definition: unit_binder.h:226
wxWindow * m_valueCtrl
Definition: unit_binder.h:215
bool m_allowEval
Definition: unit_binder.h:227

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

◆ GetValue()

long long int UNIT_BINDER::GetValue ( )
virtual

Return the current value in Internal Units.

Definition at line 337 of file unit_binder.cpp.

338 {
339  wxTextEntry* textEntry = dynamic_cast<wxTextEntry*>( m_valueCtrl );
340  wxStaticText* staticText = dynamic_cast<wxStaticText*>( m_valueCtrl );
341  wxString value;
342 
343  if( textEntry )
344  {
345  if( m_needsEval && m_eval.Process( textEntry->GetValue() ) )
346  value = m_eval.Result();
347  else
348  value = textEntry->GetValue();
349  }
350  else if( staticText )
351  {
352  value = staticText->GetLabel();
353  }
354  else
355  {
356  return 0;
357  }
358 
359  long long int displayValue = ValueFromString( m_units, value, m_dataType );
360  return m_originTransforms.FromDisplay( displayValue, m_coordType );
361 }
ORIGIN_TRANSFORMS::COORD_TYPES_T m_coordType
Type of coordinate for display origin transforms.
Definition: unit_binder.h:237
ORIGIN_TRANSFORMS & m_originTransforms
A reference to an ORIGIN_TRANSFORMS object.
Definition: unit_binder.h:234
bool m_needsEval
Definition: unit_binder.h:228
EDA_UNITS m_units
Definition: unit_binder.h:219
bool Process(const wxString &aString)
long long int ValueFromString(EDA_UNITS aUnits, const wxString &aTextValue, EDA_DATA_TYPE aType)
Function ValueFromString converts aTextValue in aUnits to internal units used by the application.
Definition: base_units.cpp:411
EDA_DATA_TYPE m_dataType
Definition: unit_binder.h:221
NUMERIC_EVALUATOR m_eval
Definition: unit_binder.h:226
wxWindow * m_valueCtrl
Definition: unit_binder.h:215
wxString Result() const
virtual int FromDisplay(int aValue, COORD_TYPES_T aCoordType) const

References ORIGIN_TRANSFORMS::FromDisplay(), m_coordType, m_dataType, m_eval, m_needsEval, m_originTransforms, m_units, m_valueCtrl, 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(), PROPERTIES_FRAME::CopyPrmsFromPanelToGeneral(), PROPERTIES_FRAME::CopyPrmsFromPanelToItem(), DIALOG_TRACK_VIA_PROPERTIES::DIALOG_TRACK_VIA_PROPERTIES(), DIALOG_PAGES_SETTINGS::GetCustomSizeMilsFromDialog(), DIALOG_LIB_NEW_SYMBOL::GetPinTextPosition(), DIALOG_PLOT_SCHEMATIC::getPlotOptions(), WX_UNIT_ENTRY_DIALOG::GetValue(), DIALOG_PAD_PROPERTIES::onCornerRadiusChange(), DIALOG_PAD_PRIMITIVE_POLY_PROPS::onPaintPolyPanel(), DIALOG_PIN_PROPERTIES::OnPropertiesChange(), onUnitsChanged(), DIALOG_PAD_PROPERTIES::PadTypeSelected(), DIALOG_PAD_PROPERTIES::padValuesOK(), DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS::processItem(), DIALOG_PLOT_SCHEMATIC::setHpglPenWidth(), PANEL_EESCHEMA_EDITING_OPTIONS::TransferDataFromWindow(), PANEL_SYM_EDITING_OPTIONS::TransferDataFromWindow(), PANEL_SETUP_FORMATTING::TransferDataFromWindow(), DIALOG_GRID_SETTINGS::TransferDataFromWindow(), DIALOG_JUNCTION_PROPS::TransferDataFromWindow(), DIALOG_TRACK_VIA_SIZE::TransferDataFromWindow(), DIALOG_LINE_WIRE_BUS_PROPERTIES::TransferDataFromWindow(), DIALOG_TRACK_VIA_PROPERTIES::TransferDataFromWindow(), DIALOG_PNS_DIFF_PAIR_DIMENSIONS::TransferDataFromWindow(), DIALOG_LIB_TEXT_PROPERTIES::TransferDataFromWindow(), DIALOG_SHEET_PIN_PROPERTIES::TransferDataFromWindow(), PANEL_SETUP_TEXT_AND_GRAPHICS::TransferDataFromWindow(), DIALOG_LIB_SHAPE_PROPERTIES::TransferDataFromWindow(), DIALOG_LIB_SYMBOL_PROPERTIES::TransferDataFromWindow(), DIALOG_PNS_LENGTH_TUNING_SETTINGS::TransferDataFromWindow(), DIALOG_TARGET_PROPERTIES::TransferDataFromWindow(), PANEL_SETUP_CONSTRAINTS::TransferDataFromWindow(), DIALOG_NON_COPPER_ZONES_EDITOR::TransferDataFromWindow(), PANEL_SETUP_MASK_AND_PASTE::TransferDataFromWindow(), DIALOG_TEXT_PROPERTIES::TransferDataFromWindow(), DIALOG_FIELD_PROPERTIES::TransferDataFromWindow(), DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::TransferDataFromWindow(), DIALOG_TEXT_AND_LABEL_PROPERTIES::TransferDataFromWindow(), DIALOG_PIN_PROPERTIES::TransferDataFromWindow(), DIALOG_FOOTPRINT_PROPERTIES::TransferDataFromWindow(), DIALOG_CREATE_ARRAY::TransferDataFromWindow(), DIALOG_SHEET_PROPERTIES::TransferDataFromWindow(), DIALOG_GRAPHIC_ITEM_PROPERTIES::TransferDataFromWindow(), MWAVE_POLYGONAL_SHAPE_DLG::TransferDataFromWindow(), DIALOG_COPPER_ZONE::TransferDataFromWindow(), DIALOG_PAD_PRIMITIVES_PROPERTIES::TransferDataFromWindow(), DIALOG_PAD_PRIMITIVE_POLY_PROPS::TransferDataFromWindow(), DIALOG_PAD_PROPERTIES::transferDataToPad(), DIALOG_PAD_PRIMITIVES_TRANSFORM::Transform(), DIALOG_DIMENSION_PROPERTIES::updateDimensionFromDialog(), DIALOG_GRAPHIC_ITEM_PROPERTIES::Validate(), Validate(), and DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS::visitItem().

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

410 {
411  wxTextEntry* te = dynamic_cast<wxTextEntry*>( m_valueCtrl );
412 
413  if( te )
414  return te->GetValue() == INDETERMINATE_STATE || te->GetValue() == INDETERMINATE_ACTION;
415 
416  return false;
417 }
wxWindow * m_valueCtrl
Definition: unit_binder.h:215
#define INDETERMINATE_ACTION
Definition: base_units.h:48
#define INDETERMINATE_STATE
Used for holding indeterminate values, such as with multiple selections holding different values or c...
Definition: base_units.h:47

References INDETERMINATE_ACTION, INDETERMINATE_STATE, and m_valueCtrl.

Referenced by DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS::processItem(), DIALOG_JUNCTION_PROPS::TransferDataFromWindow(), DIALOG_LINE_WIRE_BUS_PROPERTIES::TransferDataFromWindow(), DIALOG_TRACK_VIA_PROPERTIES::TransferDataFromWindow(), and DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS::visitItem().

◆ onKillFocus()

void UNIT_BINDER::onKillFocus ( wxFocusEvent &  aEvent)
protected

Definition at line 154 of file unit_binder.cpp.

155 {
156  wxTextEntry* textEntry = dynamic_cast<wxTextEntry*>( m_valueCtrl );
157 
158  if( m_allowEval && textEntry )
159  {
160  if( m_eval.Process( textEntry->GetValue() ) )
161  {
162  textEntry->GetSelection( &m_selStart, &m_selEnd );
163  wxString sel = textEntry->GetStringSelection();
164 
165  textEntry->ChangeValue( m_eval.Result() );
166 
167 #ifdef __WXGTK__
168  // Manually copy the selected text to the primary selection clipboard
169  if( wxTheClipboard->Open() )
170  {
171  bool clipTarget = wxTheClipboard->IsUsingPrimarySelection();
172  wxTheClipboard->UsePrimarySelection( true );
173  wxTheClipboard->SetData( new wxTextDataObject( sel ) );
174  wxTheClipboard->UsePrimarySelection( clipTarget );
175  wxTheClipboard->Close();
176  }
177 #endif
178  }
179 
180  m_needsEval = false;
181  }
182 
183  aEvent.Skip();
184 }
bool m_needsEval
Definition: unit_binder.h:228
bool Process(const wxString &aString)
NUMERIC_EVALUATOR m_eval
Definition: unit_binder.h:226
wxWindow * m_valueCtrl
Definition: unit_binder.h:215
bool m_allowEval
Definition: unit_binder.h:227
wxString Result() const
long m_selStart
Selection start and end of the original text.
Definition: unit_binder.h:230

References m_allowEval, m_eval, m_needsEval, m_selEnd, m_selStart, m_valueCtrl, NUMERIC_EVALUATOR::Process(), and NUMERIC_EVALUATOR::Result().

Referenced by UNIT_BINDER().

◆ onSetFocus()

void UNIT_BINDER::onSetFocus ( wxFocusEvent &  aEvent)
protected

Definition at line 133 of file unit_binder.cpp.

134 {
135  wxTextEntry* textEntry = dynamic_cast<wxTextEntry*>( m_valueCtrl );
136 
137  if( m_allowEval && textEntry )
138  {
139  wxString oldStr = m_eval.OriginalText();
140 
141  if( oldStr.length() && oldStr != textEntry->GetValue() )
142  {
143  textEntry->SetValue( oldStr );
144  textEntry->SetSelection( m_selStart, m_selEnd );
145  }
146 
147  m_needsEval = true;
148  }
149 
150  aEvent.Skip();
151 }
wxString OriginalText() const
bool m_needsEval
Definition: unit_binder.h:228
NUMERIC_EVALUATOR m_eval
Definition: unit_binder.h:226
wxWindow * m_valueCtrl
Definition: unit_binder.h:215
bool m_allowEval
Definition: unit_binder.h:227
long m_selStart
Selection start and end of the original text.
Definition: unit_binder.h:230

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

Referenced by UNIT_BINDER().

◆ onUnitsChanged()

void UNIT_BINDER::onUnitsChanged ( wxCommandEvent &  aEvent)
protected

Definition at line 116 of file unit_binder.cpp.

117 {
121  {
122  int temp = (int) GetValue();
123 
125 
126  SetValue( temp );
127  }
128 
129  aEvent.Skip();
130 }
EDA_DRAW_FRAME * m_frame
The bound widgets.
Definition: unit_binder.h:211
EDA_UNITS m_units
Definition: unit_binder.h:219
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 DE...
Definition: unit_binder.cpp:92
virtual void SetValue(long long int aValue)
Set new value (in Internal Units) for the text field, taking care of units conversion.
virtual long long int GetValue()
Return the current value in Internal Units.
EDA_UNITS GetUserUnits() const
Return the user units currently in use.

References DEGREES, EDA_BASE_FRAME::GetUserUnits(), GetValue(), m_frame, m_units, PERCENT, SetUnits(), SetValue(), and UNSCALED.

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

◆ RequireEval()

void UNIT_BINDER::RequireEval ( )
inline

Force the binder to evaluate the text.

Definition at line 185 of file unit_binder.h.

186  {
187  m_needsEval = true;
188  }
bool m_needsEval
Definition: unit_binder.h:228

References m_needsEval.

Referenced by DIALOG_MOVE_EXACT::DIALOG_MOVE_EXACT().

◆ SetCoordType()

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

108 {
109  m_dataType = aDataType;
110 
111  if( m_unitLabel )
113 }
wxString GetAbbreviatedUnitsLabel(EDA_UNITS aUnit, EDA_DATA_TYPE aType)
Get the units string for a given units type.
Definition: base_units.cpp:419
EDA_UNITS m_units
Definition: unit_binder.h:219
EDA_DATA_TYPE m_dataType
Definition: unit_binder.h:221
wxStaticText * m_unitLabel
Can be nullptr.
Definition: unit_binder.h:216

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

Referenced by DIALOG_COPPER_ZONE::TransferDataToWindow().

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

266 {
267  double displayValue = m_originTransforms.ToDisplay( aValue, m_coordType );
268  displayValue = setPrecision( displayValue, false );
269 
270  if( displayValue == 0 && m_negativeZero )
271  SetValue( wxT( "-" ) + StringFromValue( m_units, displayValue, false, m_dataType ) );
272  else
273  SetValue( StringFromValue( m_units, displayValue, false, m_dataType ) );
274 }
ORIGIN_TRANSFORMS::COORD_TYPES_T m_coordType
Type of coordinate for display origin transforms.
Definition: unit_binder.h:237
ORIGIN_TRANSFORMS & m_originTransforms
A reference to an ORIGIN_TRANSFORMS object.
Definition: unit_binder.h:234
EDA_UNITS m_units
Definition: unit_binder.h:219
EDA_DATA_TYPE m_dataType
Definition: unit_binder.h:221
bool m_negativeZero
Indicates "-0" should be displayed for 0.
Definition: unit_binder.h:220
virtual int ToDisplay(int aValue, COORD_TYPES_T aCoordType) const
virtual void SetValue(long long int aValue)
Set new value (in Internal Units) for the text field, taking care of units conversion.
wxString StringFromValue(EDA_UNITS aUnits, double aValue, bool aAddUnitSymbol, EDA_DATA_TYPE aType)
Convert a value to a string using double notation.
Definition: base_units.cpp:204
double setPrecision(double aValue, bool aValueUsesUserUnits)
When m_precision > 0 truncate the value aValue to show only m_precision digits in mantissa.

References m_coordType, m_dataType, m_negativeZero, m_originTransforms, m_units, setPrecision(), SetValue(), StringFromValue(), and ORIGIN_TRANSFORMS::ToDisplay().

Referenced by PROPERTIES_FRAME::CopyPrmsFromGeneralToPanel(), PROPERTIES_FRAME::CopyPrmsFromItemToPanel(), DIALOG_POSITION_RELATIVE::DIALOG_POSITION_RELATIVE(), DIALOG_POSITION_RELATIVE::OnClear(), DIALOG_PAD_PROPERTIES::onCornerSizePercentChange(), DIALOG_POSITION_RELATIVE::OnPolarChanged(), DIALOG_MOVE_EXACT::OnPolarChanged(), PANEL_SETUP_MASK_AND_PASTE::TransferDataToWindow(), DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::TransferDataToWindow(), DIALOG_TEXT_PROPERTIES::TransferDataToWindow(), DIALOG_FOOTPRINT_PROPERTIES::TransferDataToWindow(), and DIALOG_COPPER_ZONE::TransferDataToWindow().

◆ SetLabel()

void UNIT_BINDER::SetLabel ( const wxString &  aLabel)

Definition at line 436 of file unit_binder.cpp.

437 {
438  m_label->SetLabel( aLabel );
439 }
wxStaticText * m_label
Definition: unit_binder.h:214

References m_label.

Referenced by DIALOG_POSITION_RELATIVE::updateDialogControls(), and DIALOG_MOVE_EXACT::updateDialogControls().

◆ SetNegativeZero()

virtual void UNIT_BINDER::SetNegativeZero ( )
inlinevirtual

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

102 {
103  m_precision = std::min( aLength, 6 );
104 }
int m_precision
0 to 6
Definition: unit_binder.h:222

References m_precision.

Referenced by DIALOG_PAD_PROPERTIES::DIALOG_PAD_PROPERTIES(), and DIALOG_TEXT_PROPERTIES::DIALOG_TEXT_PROPERTIES().

◆ setPrecision()

double UNIT_BINDER::setPrecision ( double  aValue,
bool  aValueUsesUserUnits 
)
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 364 of file unit_binder.cpp.

365 {
366  if( m_precision > 1 )
367  {
368  int scale = pow( 10, m_precision );
369  long long tmp = aValueUsesUserUnits ? aValue : To_User_Unit( m_units, aValue ) * scale;
370  aValue = static_cast<double>( tmp ) / scale;
371 
372  if( !aValueUsesUserUnits )
373  aValue = From_User_Unit( m_units, aValue );
374  }
375 
376  return aValue;
377 }
EDA_UNITS m_units
Definition: unit_binder.h:219
int m_precision
0 to 6
Definition: unit_binder.h:222
double To_User_Unit(EDA_UNITS aUnit, double aValue)
Function To_User_Unit convert aValue in internal units to the appropriate user units defined by aUnit...
Definition: base_units.cpp:68
const int scale
double From_User_Unit(EDA_UNITS aUnits, double aValue)
Return in internal units the value "val" given in a real unit such as "in", "mm" or "deg".
Definition: base_units.cpp:277

References From_User_Unit(), m_precision, m_units, scale, and To_User_Unit().

Referenced by ChangeDoubleValue(), GetDoubleValue(), 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 92 of file unit_binder.cpp.

93 {
94  m_units = aUnits;
95 
96  if( m_unitLabel )
98 }
wxString GetAbbreviatedUnitsLabel(EDA_UNITS aUnit, EDA_DATA_TYPE aType)
Get the units string for a given units type.
Definition: base_units.cpp:419
EDA_UNITS m_units
Definition: unit_binder.h:219
EDA_DATA_TYPE m_dataType
Definition: unit_binder.h:221
wxStaticText * m_unitLabel
Can be nullptr.
Definition: unit_binder.h:216

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

Referenced by DIALOG_CREATE_ARRAY::DIALOG_CREATE_ARRAY(), DIALOG_FOOTPRINT_PROPERTIES::DIALOG_FOOTPRINT_PROPERTIES(), DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR(), DIALOG_GRAPHIC_ITEM_PROPERTIES::DIALOG_GRAPHIC_ITEM_PROPERTIES(), DIALOG_MOVE_EXACT::DIALOG_MOVE_EXACT(), DIALOG_PAD_PRIMITIVES_TRANSFORM::DIALOG_PAD_PRIMITIVES_TRANSFORM(), DIALOG_PAD_PROPERTIES::DIALOG_PAD_PROPERTIES(), DIALOG_PNS_LENGTH_TUNING_SETTINGS::DIALOG_PNS_LENGTH_TUNING_SETTINGS(), DIALOG_TEXT_PROPERTIES::DIALOG_TEXT_PROPERTIES(), onUnitsChanged(), PANEL_SETUP_MASK_AND_PASTE::PANEL_SETUP_MASK_AND_PASTE(), 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 ( long long int  aValue)
virtual

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

Definition at line 253 of file unit_binder.cpp.

254 {
255  double value = aValue;
256  double displayValue = m_originTransforms.ToDisplay( value, m_coordType );
257 
258  if( displayValue == 0 && m_negativeZero )
259  SetValue( wxT( "-" ) + StringFromValue( m_units, displayValue, false, m_dataType ) );
260  else
261  SetValue( StringFromValue( m_units, displayValue, false, m_dataType ) );
262 }
ORIGIN_TRANSFORMS::COORD_TYPES_T m_coordType
Type of coordinate for display origin transforms.
Definition: unit_binder.h:237
ORIGIN_TRANSFORMS & m_originTransforms
A reference to an ORIGIN_TRANSFORMS object.
Definition: unit_binder.h:234
EDA_UNITS m_units
Definition: unit_binder.h:219
EDA_DATA_TYPE m_dataType
Definition: unit_binder.h:221
bool m_negativeZero
Indicates "-0" should be displayed for 0.
Definition: unit_binder.h:220
virtual int ToDisplay(int aValue, COORD_TYPES_T aCoordType) const
virtual void SetValue(long long int aValue)
Set new value (in Internal Units) for the text field, taking care of units conversion.
wxString StringFromValue(EDA_UNITS aUnits, double aValue, bool aAddUnitSymbol, EDA_DATA_TYPE aType)
Convert a value to a string using double notation.
Definition: base_units.cpp:204

References m_coordType, m_dataType, m_negativeZero, m_originTransforms, m_units, StringFromValue(), and ORIGIN_TRANSFORMS::ToDisplay().

Referenced by DIALOG_COPPER_ZONE::AcceptOptions(), DIALOG_PLOT::applyPlotSettings(), DIALOG_CREATE_ARRAY::calculateCircularArrayProperties(), DIALOG_LIB_NEW_SYMBOL::DIALOG_LIB_NEW_SYMBOL(), DIALOG_MOVE_EXACT::DIALOG_MOVE_EXACT(), DIALOG_TRACK_VIA_PROPERTIES::DIALOG_TRACK_VIA_PROPERTIES(), PANEL_SETUP_FORMATTING::ImportSettingsFrom(), DIALOG_PLOT::init_Dialog(), DIALOG_PLOT_SCHEMATIC::initDlg(), DIALOG_POSITION_RELATIVE::OnClear(), DIALOG_MOVE_EXACT::OnClear(), DIALOG_PAD_PROPERTIES::OnOffsetCheckbox(), DIALOG_PAD_PROPERTIES::OnPadToDieCheckbox(), DIALOG_GRID_SETTINGS::OnResetGridOriginClick(), onUnitsChanged(), MWAVE_POLYGONAL_SHAPE_DLG::ReadDataShapeDescr(), DIALOG_JUNCTION_PROPS::resetDefaults(), DIALOG_LINE_WIRE_BUS_PROPERTIES::resetDefaults(), SetDoubleValue(), DIALOG_LIB_NEW_SYMBOL::SetPinTextPosition(), PANEL_EESCHEMA_EDITING_OPTIONS::TransferDataToWindow(), PANEL_SYM_EDITING_OPTIONS::TransferDataToWindow(), PANEL_SETUP_FORMATTING::TransferDataToWindow(), DIALOG_JUNCTION_PROPS::TransferDataToWindow(), DIALOG_GRID_SETTINGS::TransferDataToWindow(), DIALOG_LINE_WIRE_BUS_PROPERTIES::TransferDataToWindow(), DIALOG_TRACK_VIA_SIZE::TransferDataToWindow(), DIALOG_SHEET_PIN_PROPERTIES::TransferDataToWindow(), DIALOG_LIB_TEXT_PROPERTIES::TransferDataToWindow(), DIALOG_DIMENSION_PROPERTIES::TransferDataToWindow(), PANEL_SETUP_TEXT_AND_GRAPHICS::TransferDataToWindow(), DIALOG_PNS_DIFF_PAIR_DIMENSIONS::TransferDataToWindow(), DIALOG_LIB_SHAPE_PROPERTIES::TransferDataToWindow(), DIALOG_PNS_LENGTH_TUNING_SETTINGS::TransferDataToWindow(), DIALOG_TARGET_PROPERTIES::TransferDataToWindow(), PANEL_SETUP_CONSTRAINTS::TransferDataToWindow(), DIALOG_NON_COPPER_ZONES_EDITOR::TransferDataToWindow(), PANEL_SETUP_MASK_AND_PASTE::TransferDataToWindow(), DIALOG_FIELD_PROPERTIES::TransferDataToWindow(), DIALOG_TEXT_PROPERTIES::TransferDataToWindow(), DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::TransferDataToWindow(), DIALOG_TEXT_AND_LABEL_PROPERTIES::TransferDataToWindow(), DIALOG_FOOTPRINT_PROPERTIES::TransferDataToWindow(), DIALOG_PIN_PROPERTIES::TransferDataToWindow(), DIALOG_SHEET_PROPERTIES::TransferDataToWindow(), DIALOG_PAGES_SETTINGS::TransferDataToWindow(), DIALOG_GRAPHIC_ITEM_PROPERTIES::TransferDataToWindow(), DIALOG_COPPER_ZONE::TransferDataToWindow(), DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS::TransferDataToWindow(), DIALOG_PAD_PRIMITIVES_PROPERTIES::TransferDataToWindow(), DIALOG_PAD_PRIMITIVE_POLY_PROPS::TransferDataToWindow(), and WX_UNIT_ENTRY_DIALOG::WX_UNIT_ENTRY_DIALOG().

◆ SetValue() [2/2]

void UNIT_BINDER::SetValue ( const wxString &  aValue)

Definition at line 277 of file unit_binder.cpp.

278 {
279  wxTextEntry* textEntry = dynamic_cast<wxTextEntry*>( m_valueCtrl );
280  wxStaticText* staticText = dynamic_cast<wxStaticText*>( m_valueCtrl );
281 
282  if( textEntry )
283  textEntry->SetValue( aValue );
284  else if( staticText )
285  staticText->SetLabel( aValue );
286 
287  if( m_allowEval )
288  m_eval.Clear();
289 
290  if( m_unitLabel )
292 }
wxString GetAbbreviatedUnitsLabel(EDA_UNITS aUnit, EDA_DATA_TYPE aType)
Get the units string for a given units type.
Definition: base_units.cpp:419
EDA_UNITS m_units
Definition: unit_binder.h:219
EDA_DATA_TYPE m_dataType
Definition: unit_binder.h:221
wxStaticText * m_unitLabel
Can be nullptr.
Definition: unit_binder.h:216
NUMERIC_EVALUATOR m_eval
Definition: unit_binder.h:226
wxWindow * m_valueCtrl
Definition: unit_binder.h:215
bool m_allowEval
Definition: unit_binder.h:227

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

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

453 {
454  m_label->Show( aShow );
455  m_valueCtrl->Show( aShow );
456 
457  if( m_unitLabel )
458  m_unitLabel->Show( aShow );
459 
460  if( aResize )
461  {
462  if( aShow )
463  {
464  m_label->SetSize( -1, -1 );
465  m_valueCtrl->SetSize( -1, -1 );
466 
467  if( m_unitLabel )
468  m_unitLabel->SetSize( -1, -1 );
469  }
470  else
471  {
472  m_label->SetSize( 0, 0 );
473  m_valueCtrl->SetSize( 0, 0 );
474 
475  if( m_unitLabel )
476  m_unitLabel->SetSize( 0, 0 );
477  }
478  }
479 }
wxStaticText * m_label
Definition: unit_binder.h:214
wxStaticText * m_unitLabel
Can be nullptr.
Definition: unit_binder.h:216
wxWindow * m_valueCtrl
Definition: unit_binder.h:215

References m_label, m_unitLabel, and m_valueCtrl.

Referenced by PROPERTIES_FRAME::CopyPrmsFromItemToPanel(), 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 
)
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 206 of file unit_binder.cpp.

207 {
208  wxTextEntry* textEntry = dynamic_cast<wxTextEntry*>( m_valueCtrl );
209 
210  if( !textEntry
211  || textEntry->GetValue() == INDETERMINATE_ACTION
212  || textEntry->GetValue() == INDETERMINATE_STATE )
213  {
214  return true;
215  }
216 
217  // TODO: Validate() does not currently support m_dataType being anything other than DISTANCE
218  // Note: aMin and aMax are not always given in internal units
219  if( GetValue() < From_User_Unit( aUnits, aMin ) )
220  {
221  double val_min_iu = From_User_Unit( aUnits, aMin );
222  m_errorMessage = wxString::Format( _( "%s must be at least %s." ),
224  StringFromValue( m_units, val_min_iu, true ) );
225 
226  textEntry->SelectAll();
227 
228  // Don't focus directly; we might be inside a KillFocus event handler
229  wxPostEvent( this, wxCommandEvent( DELAY_FOCUS ) );
230 
231  return false;
232  }
233 
234  if( GetValue() > From_User_Unit( aUnits, aMax ) )
235  {
236  double val_max_iu = From_User_Unit( aUnits, aMax );
237  m_errorMessage = wxString::Format( _( "%s must be less than %s." ),
239  StringFromValue( m_units, val_max_iu, true ) );
240 
241  textEntry->SelectAll();
242 
243  // Don't focus directly; we might be inside a KillFocus event handler
244  wxPostEvent( this, wxCommandEvent( DELAY_FOCUS ) );
245 
246  return false;
247  }
248 
249  return true;
250 }
wxString m_errorMessage
Definition: unit_binder.h:224
wxString valueDescriptionFromLabel(wxStaticText *aLabel)
EDA_UNITS m_units
Definition: unit_binder.h:219
wxStaticText * m_label
Definition: unit_binder.h:214
#define _(s)
wxWindow * m_valueCtrl
Definition: unit_binder.h:215
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
virtual long long int GetValue()
Return the current value in Internal Units.
wxString StringFromValue(EDA_UNITS aUnits, double aValue, bool aAddUnitSymbol, EDA_DATA_TYPE aType)
Convert a value to a string using double notation.
Definition: base_units.cpp:204
#define INDETERMINATE_ACTION
Definition: base_units.h:48
#define INDETERMINATE_STATE
Used for holding indeterminate values, such as with multiple selections holding different values or c...
Definition: base_units.h:47
double From_User_Unit(EDA_UNITS aUnits, double aValue)
Return in internal units the value "val" given in a real unit such as "in", "mm" or "deg".
Definition: base_units.cpp:277

References _, Format(), From_User_Unit(), GetValue(), INDETERMINATE_ACTION, INDETERMINATE_STATE, m_errorMessage, m_label, m_units, m_valueCtrl, StringFromValue(), and valueDescriptionFromLabel().

Referenced by DIALOG_PNS_LENGTH_TUNING_SETTINGS::AcceptOptions(), DIALOG_COPPER_ZONE::AcceptOptions(), DIALOG_GRID_SETTINGS::TransferDataFromWindow(), DIALOG_TRACK_VIA_PROPERTIES::TransferDataFromWindow(), DIALOG_TARGET_PROPERTIES::TransferDataFromWindow(), PANEL_SETUP_CONSTRAINTS::TransferDataFromWindow(), DIALOG_NON_COPPER_ZONES_EDITOR::TransferDataFromWindow(), DIALOG_TEXT_PROPERTIES::TransferDataFromWindow(), DIALOG_TEXT_AND_LABEL_PROPERTIES::TransferDataFromWindow(), DIALOG_PAGES_SETTINGS::TransferDataFromWindow(), DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS::TransferDataFromWindow(), DIALOG_PAD_PROPERTIES::transferDataToPad(), DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::Validate(), and DIALOG_FOOTPRINT_PROPERTIES::Validate().

Member Data Documentation

◆ m_allowEval

bool UNIT_BINDER::m_allowEval
protected

◆ m_coordType

ORIGIN_TRANSFORMS::COORD_TYPES_T UNIT_BINDER::m_coordType
protected

Type of coordinate for display origin transforms.

Definition at line 237 of file unit_binder.h.

Referenced by ChangeDoubleValue(), ChangeValue(), GetCoordType(), GetDoubleValue(), GetValue(), SetCoordType(), SetDoubleValue(), and SetValue().

◆ m_dataType

EDA_DATA_TYPE UNIT_BINDER::m_dataType
protected

◆ m_errorMessage

wxString UNIT_BINDER::m_errorMessage
protected

Definition at line 224 of file unit_binder.h.

Referenced by delayedFocusHandler(), and Validate().

◆ m_eval

NUMERIC_EVALUATOR UNIT_BINDER::m_eval
protected

◆ m_frame

EDA_DRAW_FRAME* UNIT_BINDER::m_frame
protected

The bound widgets.

Definition at line 211 of file unit_binder.h.

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

◆ m_label

wxStaticText* UNIT_BINDER::m_label
protected

Definition at line 214 of file unit_binder.h.

Referenced by Enable(), SetLabel(), Show(), 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 220 of file unit_binder.h.

Referenced by ChangeDoubleValue(), ChangeValue(), SetDoubleValue(), SetNegativeZero(), SetValue(), and UNIT_BINDER().

◆ m_originTransforms

ORIGIN_TRANSFORMS& UNIT_BINDER::m_originTransforms
protected

A reference to an ORIGIN_TRANSFORMS object.

Definition at line 234 of file unit_binder.h.

Referenced by ChangeDoubleValue(), ChangeValue(), GetDoubleValue(), GetValue(), SetDoubleValue(), and SetValue().

◆ m_precision

int UNIT_BINDER::m_precision
protected

0 to 6

Definition at line 222 of file unit_binder.h.

Referenced by SetPrecision(), and setPrecision().

◆ m_selEnd

long UNIT_BINDER::m_selEnd
protected

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

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

◆ m_unitLabel

wxStaticText* UNIT_BINDER::m_unitLabel
protected

Can be nullptr.

Currently used units.

Definition at line 216 of file unit_binder.h.

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

◆ m_units

◆ m_valueCtrl


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