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, you may find one here:
20 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21 * or you may search the http://www.gnu.org website for the version 2 license,
22 * or you may write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 */
25
26#ifndef __UNIT_BINDER_H_
27#define __UNIT_BINDER_H_
28
29#include <span>
30
31#include <base_units.h>
32#include <units_provider.h>
34#include <wx/event.h>
35
36class EDA_BASE_FRAME;
37class EDA_DRAW_FRAME;
38class wxTextEntry;
39class wxSpinButton;
40class wxStaticText;
41
42class UNIT_BINDER : public wxEvtHandler
43{
44public:
45
58 wxStaticText* aLabel, wxWindow* aValueCtrl, wxStaticText* aUnitLabel,
59 bool aAllowEval = true, bool aBindFocusEvent = true );
60
61 UNIT_BINDER( UNITS_PROVIDER* aUnitsProvider, wxWindow* aEventSource,
62 wxStaticText* aLabel, wxWindow* aValueCtrl, wxStaticText* aUnitLabel,
63 bool aAllowEval = true, bool aBindFocusEvent = true );
64
65 virtual ~UNIT_BINDER() override;
66
71 virtual void SetUnits( EDA_UNITS aUnits );
72
73 virtual void SetNegativeZero() { m_negativeZero = true; }
74
82 virtual void SetPrecision( int aLength );
83
88 void SetDataType( EDA_DATA_TYPE aDataType );
89
93 virtual void SetValue( long long int aValue );
94
95 void SetValue( const wxString& aValue );
96
102 virtual void SetDoubleValue( double aValue );
103
104 virtual void SetAngleValue( const EDA_ANGLE& aValue );
105
110 virtual void ChangeValue( int aValue );
111
112 void ChangeValue( const wxString& aValue );
113
120 virtual void ChangeDoubleValue( double aValue );
121
122 virtual void ChangeAngleValue( const EDA_ANGLE& aValue );
123
127 virtual long long int GetValue();
128
129 int GetIntValue() { return (int) GetValue(); }
130
137 virtual double GetDoubleValue();
138
139 virtual EDA_ANGLE GetAngleValue();
140
146 virtual void SetOptionsList( std::span<const long long int> aOptions );
147 virtual void SetDoubleOptionsList( std::span<const double> aOptions );
148
149
154 bool IsIndeterminate() const;
155
159 bool IsNull() const;
160 void SetNull();
161
170 virtual bool Validate( double aMin, double aMax, EDA_UNITS aUnits = EDA_UNITS::UNSCALED );
171
172 void SetLabel( const wxString& aLabel );
173
177 void Enable( bool aEnable );
178
185 void Show( bool aShow, bool aResize = false );
186
193 {
194 return m_coordType;
195 }
196
201 {
202 m_coordType = aCoordType;
203 }
204
209 {
210 m_needsEval = true;
211 }
212
213protected:
214 void init( UNITS_PROVIDER* aProvider );
215 void onClick( wxMouseEvent& aEvent );
216 void onComboBox( wxCommandEvent& aEvent );
217
218 void onSetFocus( wxFocusEvent& aEvent );
219 void onKillFocus( wxFocusEvent& aEvent );
220 void delayedFocusHandler( wxCommandEvent& aEvent );
221
222 void onUnitsChanged( wxCommandEvent& aEvent );
223
235 double setPrecision( double aValue, bool aValueUsesUserUnits ) const;
236
237 wxString getTextForValue( long long int aValue ) const;
238 wxString getTextForDoubleValue( double aValue ) const;
239
240protected:
242
244 wxStaticText* m_label;
245 wxWindow* m_valueCtrl;
246 wxStaticText* m_unitLabel;
247
254
256
260
263
265
268
271};
272
273
278{
279public:
281
283
284 void SetControl( wxWindow* aControl );
285};
286
287#endif /* __UNIT_BINDER_H_ */
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.
Specialization for wxPropertyGrid, where we have no labels and units are displayed in the editor.
Definition: unit_binder.h:278
void SetControl(wxWindow *aControl)
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.
Definition: unit_binder.h:270
wxString getTextForValue(long long int aValue) const
int GetIntValue()
Definition: unit_binder.h:129
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...
bool m_allowEval
Definition: unit_binder.h:258
wxString getTextForDoubleValue(double aValue) const
const EDA_IU_SCALE * m_iuScale
Currently used units.
Definition: unit_binder.h:249
wxString m_errorMessage
Definition: unit_binder.h:255
virtual EDA_ANGLE GetAngleValue()
bool m_negativeZero
Indicates "-0" should be displayed for 0.
Definition: unit_binder.h:251
int m_precision
0 to 6.
Definition: unit_binder.h:253
wxStaticText * m_unitLabel
Can be nullptr.
Definition: unit_binder.h:246
virtual void SetNegativeZero()
Definition: unit_binder.h:73
bool m_unitsInValue
Units label should be included in value text.
Definition: unit_binder.h:264
wxWindow * m_valueCtrl
Definition: unit_binder.h:245
void onSetFocus(wxFocusEvent &aEvent)
void onComboBox(wxCommandEvent &aEvent)
wxStaticText * m_label
The bound widgets.
Definition: unit_binder.h:244
ORIGIN_TRANSFORMS & m_originTransforms
A reference to an ORIGIN_TRANSFORMS object.
Definition: unit_binder.h:267
bool m_bindFocusEvent
Definition: unit_binder.h:241
long m_selStart
Selection start and end of the original text.
Definition: unit_binder.h:261
virtual void SetDoubleOptionsList(std::span< const double > aOptions)
EDA_UNITS m_units
Definition: unit_binder.h:250
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...
bool m_needsEval
Definition: unit_binder.h:259
void SetDataType(EDA_DATA_TYPE aDataType)
Used to override the datatype of the displayed property (default is DISTANCE)
void RequireEval()
Force the binder to evaluate the text.
Definition: unit_binder.h:208
void delayedFocusHandler(wxCommandEvent &aEvent)
EDA_DATA_TYPE m_dataType
Definition: unit_binder.h:252
ORIGIN_TRANSFORMS::COORD_TYPES_T GetCoordType() const
Get the origin transforms coordinate type.
Definition: unit_binder.h:192
virtual void SetAngleValue(const EDA_ANGLE &aValue)
void SetLabel(const wxString &aLabel)
void init(UNITS_PROVIDER *aProvider)
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 SetNull()
virtual ~UNIT_BINDER() override
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
Definition: unit_binder.h:257
void SetCoordType(ORIGIN_TRANSFORMS::COORD_TYPES_T aCoordType)
Set the current origin transform mode.
Definition: unit_binder.h:200
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:38
EDA_UNITS
Definition: eda_units.h:46