26#include <wx/clipbrd.h>
27#include <wx/combobox.h>
28#include <wx/stattext.h>
29#include <wx/textentry.h>
36#include "wx/dcclient.h"
45 wxStaticText* aUnitLabel,
bool allowEval,
bool aBindFrameEvents ) :
46 UNIT_BINDER( aParent, aParent, aLabel, aValueCtrl, aUnitLabel, allowEval, aBindFrameEvents )
51 wxStaticText* aLabel, wxWindow* aValueCtrl, wxStaticText* aUnitLabel,
52 bool aAllowEval,
bool aBindFocusEvent ) :
53 m_bindFocusEvent( aBindFocusEvent ),
55 m_valueCtrl( aValueCtrl ),
56 m_eventSource( aEventSource ),
57 m_unitLabel( aUnitLabel ),
58 m_iuScale( &aUnitsProvider->GetIuScale() ),
60 m_negativeZero( false ),
64 m_allowEval( aAllowEval && ( !m_valueCtrl || dynamic_cast<wxTextEntry*>( m_valueCtrl ) ) ),
68 m_unitsInValue( false ),
69 m_originTransforms( aUnitsProvider->GetOriginTransforms() ),
77 while( parent && !
dynamic_cast<DIALOG_SHIM*
>( parent ) )
78 parent = parent->GetParent();
84 wxTextEntry* textEntry =
dynamic_cast<wxTextEntry*
>(
m_valueCtrl );
93 int minWidth = dc.GetTextExtent( wxT(
"XXX.XXXXXXXXXX" ) ).GetWidth();
95 if(
minSize.GetWidth() < minWidth )
100 textEntry->ChangeValue( wxT(
"-0" ) );
102 textEntry->ChangeValue( wxT(
"0" ) );
183 wxComboBox*
const combo =
dynamic_cast<wxComboBox*
>(
m_valueCtrl );
184 std::vector<long long int> comboValues;
189 for(
unsigned int i = 0; i < combo->GetCount(); i++ )
191 const wxString value = combo->GetString( i );
193 comboValues.push_back( conv );
216 wxTextEntry* textEntry =
dynamic_cast<wxTextEntry*
>(
m_valueCtrl );
222 textEntry->SelectAll();
232 wxComboBox* combo =
dynamic_cast<wxComboBox*
>(
m_valueCtrl );
235 const wxString value = combo->GetStringSelection();
246 wxTextEntry* textEntry =
dynamic_cast<wxTextEntry*
>(
m_valueCtrl );
254 if( oldStr.length() && oldStr != textEntry->GetValue() )
256 textEntry->ChangeValue( oldStr );
267 textEntry->SelectAll();
277 wxTextEntry* textEntry =
dynamic_cast<wxTextEntry*
>(
m_valueCtrl );
281 wxString value = textEntry->GetValue();
284 if( success && !value.IsEmpty() )
292 if( !(
m_units == EDA_UNITS::DEGREES ||
m_units == EDA_UNITS::PERCENT ) )
298 textEntry->ChangeValue( value );
302 if( wxTheClipboard->Open() )
304 wxString sel = textEntry->GetStringSelection();
305 bool clipTarget = wxTheClipboard->IsUsingPrimarySelection();
306 wxTheClipboard->UsePrimarySelection(
true );
307 wxTheClipboard->SetData(
new wxTextDataObject( sel ) );
308 wxTheClipboard->UsePrimarySelection( clipTarget );
309 wxTheClipboard->Close();
323 wxString desc = aLabel->GetLabel();
325 desc.EndsWith( wxT(
":" ), &desc );
342 wxTextEntry* textEntry =
dynamic_cast<wxTextEntry*
>(
m_valueCtrl );
360 textEntry->SelectAll();
363 wxPostEvent(
this, wxCommandEvent( DELAY_FOCUS ) );
375 textEntry->SelectAll();
378 wxPostEvent(
this, wxCommandEvent( DELAY_FOCUS ) );
405 if( displayValue == 0 && !std::signbit( displayValue ) &&
m_negativeZero )
420 wxTextEntry* textEntry =
dynamic_cast<wxTextEntry*
>(
m_valueCtrl );
421 wxStaticText* staticText =
dynamic_cast<wxStaticText*
>(
m_valueCtrl );
423 wxString value = aValue;
427 if( !(
m_units == EDA_UNITS::DEGREES ||
m_units == EDA_UNITS::PERCENT ) )
434 textEntry->SetValue( value );
435 else if( staticText )
436 staticText->SetLabel( value );
454 textValue = wxT(
"-" ) + textValue;
466 if( displayValue == 0 && !std::signbit( displayValue ) &&
m_negativeZero )
467 textValue = wxT(
"-" ) + textValue;
493 wxTextEntry* textEntry =
dynamic_cast<wxTextEntry*
>(
m_valueCtrl );
494 wxStaticText* staticText =
dynamic_cast<wxStaticText*
>(
m_valueCtrl );
496 wxString value = aValue;
500 if( !(
m_units == EDA_UNITS::DEGREES ||
m_units == EDA_UNITS::PERCENT ) )
507 textEntry->ChangeValue( value );
508 else if( staticText )
509 staticText->SetLabel( value );
521 wxTextEntry* textEntry =
dynamic_cast<wxTextEntry*
>(
m_valueCtrl );
522 wxStaticText* staticText =
dynamic_cast<wxStaticText*
>(
m_valueCtrl );
527 value = textEntry->GetValue();
532 value = textEntry->GetValue();
534 else if( staticText )
536 value = staticText->GetLabel();
553 int64_t tmp = aValue;
555 if( !aValueUsesUserUnits )
558 aValue =
static_cast<double>( tmp ) /
scale;
560 if( !aValueUsesUserUnits )
570 wxTextEntry* textEntry =
dynamic_cast<wxTextEntry*
>(
m_valueCtrl );
571 wxStaticText* staticText =
dynamic_cast<wxStaticText*
>(
m_valueCtrl );
576 value = textEntry->GetValue();
581 value = textEntry->GetValue();
583 else if( staticText )
585 value = staticText->GetLabel();
607 wxComboBox* cb =
dynamic_cast<wxComboBox*
>(
m_valueCtrl );
612 for(
long long int value : aOptions )
619 wxComboBox* cb =
dynamic_cast<wxComboBox*
>(
m_valueCtrl );
624 for(
double value : aOptions )
631 wxTextEntry* te =
dynamic_cast<wxTextEntry*
>(
m_valueCtrl );
642 if( wxTextEntry* te =
dynamic_cast<wxTextEntry*
>(
m_valueCtrl ) )
643 return te->GetValue().IsEmpty();
651 if( wxTextEntry* te =
dynamic_cast<wxTextEntry*
>(
m_valueCtrl ) )
652 return te->SetValue( wxEmptyString );
705 UNIT_BINDER( aParent, nullptr, nullptr, nullptr, true, false )
726 [&]( wxShowEvent& e )
Dialog helper object to sit in the inheritance tree between wxDialog and any class written by wxFormB...
The base frame for deriving all KiCad main window classes.
The base class for create windows for drawing purpose.
wxString OriginalText() const
void SetDefaultUnits(EDA_UNITS aUnits)
bool Process(const wxString &aString)
void SetControl(wxWindow *aControl)
PROPERTY_EDITOR_UNIT_BINDER(EDA_DRAW_FRAME *aParent)
virtual ~PROPERTY_EDITOR_UNIT_BINDER()
const EDA_IU_SCALE & GetIuScale() const
EDA_UNITS GetUserUnits() const
double setPrecision(double aValue, bool aValueUsesUserUnits) const
When m_precision > 0 truncate the value aValue to show only m_precision digits in mantissa.
ORIGIN_TRANSFORMS::COORD_TYPES_T m_coordType
Type of coordinate for display origin transforms.
wxString getTextForValue(long long int aValue) const
virtual void ChangeDoubleValue(double aValue)
Set new value (in Internal Units) for the text field, taking care of units conversion WITHOUT trigger...
void onKillFocus(wxFocusEvent &aEvent)
virtual long long int GetValue()
Return the current value in Internal Units.
void Enable(bool aEnable)
Enable/disable the label, widget and units label.
void onClick(wxMouseEvent &aEvent)
virtual void SetPrecision(int aLength)
Normally not needed, but can be used to set the precision when using internal units that are floats (...
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...
wxString getTextForDoubleValue(double aValue) const
const EDA_IU_SCALE * m_iuScale
Currently used units.
virtual EDA_ANGLE GetAngleValue()
bool m_negativeZero
Indicates "-0" should be displayed for 0.
wxStaticText * m_unitLabel
Can be nullptr.
bool m_unitsInValue
Units label should be included in value text.
void onSetFocus(wxFocusEvent &aEvent)
void onComboBox(wxCommandEvent &aEvent)
UNIT_BINDER(EDA_DRAW_FRAME *aParent, wxStaticText *aLabel, wxWindow *aValueCtrl, wxStaticText *aUnitLabel, bool aAllowEval=true, bool aBindFocusEvent=true)
wxStaticText * m_label
The bound widgets.
ORIGIN_TRANSFORMS & m_originTransforms
A reference to an ORIGIN_TRANSFORMS object.
long m_selStart
Selection start and end of the original text.
virtual void SetDoubleOptionsList(std::span< const double > aOptions)
virtual double GetDoubleValue()
Return the current value in Internal Units.
virtual void SetOptionsList(std::span< const long long int > aOptions)
Set the list of options for a combobox control.
bool IsIndeterminate() const
Return true if the control holds the indeterminate value (for instance, if it represents a multiple s...
void SetDataType(EDA_DATA_TYPE aDataType)
Used to override the datatype of the displayed property (default is DISTANCE)
void delayedFocusHandler(wxCommandEvent &aEvent)
virtual void SetAngleValue(const EDA_ANGLE &aValue)
void SetLabel(const wxString &aLabel)
virtual void ChangeAngleValue(const EDA_ANGLE &aValue)
virtual void SetDoubleValue(double aValue)
Set new value (in Internal Units) for the text field, taking care of units conversion.
virtual ~UNIT_BINDER() override
bool UnitsInvariant() const
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.
virtual void ChangeValue(int aValue)
Set new value (in Internal Units) for the text field, taking care of units conversion WITHOUT trigger...
virtual void SetValue(long long int aValue)
Set new value (in Internal Units) for the text field, taking care of units conversion.
void Show(bool aShow, bool aResize=false)
Show/hide the label, widget and units label.
bool IsNull() const
Return true if the control holds no value (ie: empty string, not 0).
void onUnitsChanged(wxCommandEvent &aEvent)
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
This file is part of the common library.
const int minSize
Push and Shove router track width and via size dialog.
EDA_DATA_TYPE
The type of unit.
KICOMMON_API double FromUserUnit(const EDA_IU_SCALE &aIuScale, EDA_UNITS aUnit, double aValue)
Return in internal units the value aValue given in a real unit such as "in", "mm",...
KICOMMON_API long long int ValueFromString(const EDA_IU_SCALE &aIuScale, EDA_UNITS aUnits, const wxString &aTextValue, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
Convert aTextValue in aUnits to internal units used by the application.
KICOMMON_API wxString StringFromValue(const EDA_IU_SCALE &aIuScale, EDA_UNITS aUnits, double aValue, bool aAddUnitsText=false, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
Return the string from aValue according to aUnits (inch, mm ...) for display.
KICOMMON_API double DoubleValueFromString(const EDA_IU_SCALE &aIuScale, EDA_UNITS aUnits, const wxString &aTextValue, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
Convert aTextValue to a double.
KICOMMON_API double ToUserUnit(const EDA_IU_SCALE &aIuScale, EDA_UNITS aUnit, double aValue)
Convert aValue in internal units to the appropriate user units defined by aUnit.
KICOMMON_API wxString GetLabel(EDA_UNITS aUnits, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
Get the units string for a given units type.
int GetUserUnits()
Return the currently selected user unit value for the interface.
#define INDETERMINATE_ACTION
#define INDETERMINATE_STATE
Used for holding indeterminate values, such as with multiple selections holding different values or c...
wxDEFINE_EVENT(DELAY_FOCUS, wxCommandEvent)
wxString valueDescriptionFromLabel(wxStaticText *aLabel)