KiCad PCB EDA Suite
Loading...
Searching...
No Matches
unit_binder.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2014-2015 CERN
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 * Author: Maciej Suminski <[email protected]>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22#ifndef __UNIT_BINDER_H_
23#define __UNIT_BINDER_H_
24
25#include <span>
26
27#include <base_units.h>
28#include <units_provider.h>
30#include <wx/event.h>
31
32class DIALOG_SHIM;
33class EDA_BASE_FRAME;
34class EDA_DRAW_FRAME;
35class wxTextEntry;
36class wxSpinButton;
37class wxStaticText;
38
39class UNIT_BINDER : public wxEvtHandler
40{
41public:
42
55 wxStaticText* aLabel, wxWindow* aValueCtrl, wxStaticText* aUnitLabel,
56 bool aAllowEval = true, bool aBindFocusEvent = true );
57
58 UNIT_BINDER( UNITS_PROVIDER* aUnitsProvider, wxWindow* aEventSource,
59 wxStaticText* aLabel, wxWindow* aValueCtrl, wxStaticText* aUnitLabel,
60 bool aAllowEval = true, bool aBindFocusEvent = true );
61
62 virtual ~UNIT_BINDER() override;
63
68 virtual void SetUnits( EDA_UNITS aUnits );
69
74
75 virtual void SetNegativeZero() { m_negativeZero = true; }
76
84 virtual void SetPrecision( int aLength );
85
90 void SetDataType( EDA_DATA_TYPE aDataType );
91
95 virtual void SetValue( long long int aValue );
96
97 void SetValue( const wxString& aValue );
98
104 virtual void SetDoubleValue( double aValue );
105
106 virtual void SetAngleValue( const EDA_ANGLE& aValue );
107
112 virtual void ChangeValue( int aValue );
113
114 void ChangeValue( const wxString& aValue );
115
122 virtual void ChangeDoubleValue( double aValue );
123
124 virtual void ChangeAngleValue( const EDA_ANGLE& aValue );
125
129 virtual long long int GetValue() const;
130
131 int GetIntValue() const
132 {
133 const long long int value = GetValue();
134 const long long int clamped =
135 std::clamp<long long>( value, static_cast<long long>( std::numeric_limits<int>::lowest() ),
136 static_cast<long long>( std::numeric_limits<int>::max() ) );
137
138 return static_cast<int>( clamped );
139 }
140
147 virtual double GetDoubleValue() const;
148
149 virtual EDA_ANGLE GetAngleValue();
150
156 virtual void SetOptionsList( std::span<const long long int> aOptions );
157 virtual void SetDoubleOptionsList( std::span<const double> aOptions );
158
159
164 bool IsIndeterminate() const;
165
169 bool IsNull() const;
170 void SetNull();
171
180 virtual bool Validate( double aMin, double aMax, EDA_UNITS aUnits = EDA_UNITS::UNSCALED );
181
182 void SetLabel( const wxString& aLabel );
183
187 void Enable( bool aEnable );
188
195 void Show( bool aShow, bool aResize = false );
196
206
211 {
212 m_coordType = aCoordType;
213 }
214
219 {
220 m_needsEval = true;
221 }
222
223protected:
224 void onClick( wxMouseEvent& aEvent );
225 void onComboBox( wxCommandEvent& aEvent );
226
227 void onSetFocus( wxFocusEvent& aEvent );
228 void onKillFocus( wxFocusEvent& aEvent );
229 void delayedFocusHandler( wxCommandEvent& aEvent );
230
231 void onValueCtrlDestroyed( wxWindowDestroyEvent& aEvent );
232
233 void onUnitsChanged( wxCommandEvent& aEvent );
234
246 double setPrecision( double aValue, bool aValueUsesUserUnits ) const;
247
248 wxString getTextForValue( long long int aValue ) const;
249 wxString getTextForDoubleValue( double aValue ) const;
250
251protected:
253
255 wxStaticText* m_label;
256 wxWindow* m_valueCtrl;
257 wxWindow* m_eventSource;
258 wxStaticText* m_unitLabel;
259
266
268
272
275
277
280
283
286
287public:
294 void DetachFromDialogShim() { m_dialogShim = nullptr; }
295};
296
297
302{
303public:
305
307
308 void SetControl( wxWindow* aControl );
309};
310
311#endif /* __UNIT_BINDER_H_ */
Dialog helper object to sit in the inheritance tree between wxDialog and any class written by wxFormB...
Definition dialog_shim.h:65
The base frame for deriving all KiCad main window classes.
The base class for create windows for drawing purpose.
A class to perform either relative or absolute display origin transforms for a single axis of a point...
COORD_TYPES_T
The supported Display Origin Transform types.
void SetControl(wxWindow *aControl)
PROPERTY_EDITOR_UNIT_BINDER(EDA_DRAW_FRAME *aParent)
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)
void Enable(bool aEnable)
Enable/disable the label, widget and units label.
void onClick(wxMouseEvent &aEvent)
DIALOG_SHIM * m_dialogShim
The dialog this binder registered itself with, or nullptr if it isn't owned by a dialog.
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...
virtual double GetDoubleValue() const
Return the current value in Internal Units.
wxString getTextForDoubleValue(double aValue) const
const EDA_IU_SCALE * m_iuScale
Currently used units.
wxString m_errorMessage
virtual EDA_ANGLE GetAngleValue()
bool m_negativeZero
Indicates "-0" should be displayed for 0.
virtual long long int GetValue() const
Return the current value in Internal Units.
int m_precision
0 to 6.
wxStaticText * m_unitLabel
Can be nullptr.
virtual void SetNegativeZero()
Definition unit_binder.h:75
bool m_unitsInValue
Units label should be included in value text.
wxWindow * m_valueCtrl
wxWindow * m_eventSource
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.
bool m_bindFocusEvent
long m_selStart
Selection start and end of the original text.
virtual void SetDoubleOptionsList(std::span< const double > aOptions)
void onValueCtrlDestroyed(wxWindowDestroyEvent &aEvent)
EDA_UNITS m_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)
int GetIntValue() const
void RequireEval()
Force the binder to evaluate the text.
void delayedFocusHandler(wxCommandEvent &aEvent)
EDA_DATA_TYPE m_dataType
ORIGIN_TRANSFORMS::COORD_TYPES_T GetCoordType() const
Get the origin transforms coordinate type.
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.
void DetachFromDialogShim()
Sever the back-reference to the owning dialog.
virtual ~UNIT_BINDER() override
bool UnitsInvariant() const
Definition unit_binder.h:70
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.
NUMERIC_EVALUATOR m_eval
void SetCoordType(ORIGIN_TRANSFORMS::COORD_TYPES_T aCoordType)
Set the current origin transform mode.
bool IsNull() const
Return true if the control holds no value (ie: empty string, not 0).
void onUnitsChanged(wxCommandEvent &aEvent)
EDA_DATA_TYPE
The type of unit.
Definition eda_units.h:34
EDA_UNITS
Definition eda_units.h:44