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 bool UnitsInvariant() const
74 {
75 return m_units == EDA_UNITS::UNSCALED || m_units == EDA_UNITS::DEGREES || m_units == EDA_UNITS::PERCENT;
76 }
77
78 virtual void SetNegativeZero() { m_negativeZero = true; }
79
87 virtual void SetPrecision( int aLength );
88
93 void SetDataType( EDA_DATA_TYPE aDataType );
94
98 virtual void SetValue( long long int aValue );
99
100 void SetValue( const wxString& aValue );
101
107 virtual void SetDoubleValue( double aValue );
108
109 virtual void SetAngleValue( const EDA_ANGLE& aValue );
110
115 virtual void ChangeValue( int aValue );
116
117 void ChangeValue( const wxString& aValue );
118
125 virtual void ChangeDoubleValue( double aValue );
126
127 virtual void ChangeAngleValue( const EDA_ANGLE& aValue );
128
132 virtual long long int GetValue();
133
134 int GetIntValue() { return (int) GetValue(); }
135
142 virtual double GetDoubleValue();
143
144 virtual EDA_ANGLE GetAngleValue();
145
151 virtual void SetOptionsList( std::span<const long long int> aOptions );
152 virtual void SetDoubleOptionsList( std::span<const double> aOptions );
153
154
159 bool IsIndeterminate() const;
160
164 bool IsNull() const;
165 void SetNull();
166
175 virtual bool Validate( double aMin, double aMax, EDA_UNITS aUnits = EDA_UNITS::UNSCALED );
176
177 void SetLabel( const wxString& aLabel );
178
182 void Enable( bool aEnable );
183
190 void Show( bool aShow, bool aResize = false );
191
198 {
199 return m_coordType;
200 }
201
206 {
207 m_coordType = aCoordType;
208 }
209
214 {
215 m_needsEval = true;
216 }
217
218protected:
219 void onClick( wxMouseEvent& aEvent );
220 void onComboBox( wxCommandEvent& aEvent );
221
222 void onSetFocus( wxFocusEvent& aEvent );
223 void onKillFocus( wxFocusEvent& aEvent );
224 void delayedFocusHandler( wxCommandEvent& aEvent );
225
226 void onUnitsChanged( wxCommandEvent& aEvent );
227
239 double setPrecision( double aValue, bool aValueUsesUserUnits ) const;
240
241 wxString getTextForValue( long long int aValue ) const;
242 wxString getTextForDoubleValue( double aValue ) const;
243
244protected:
246
248 wxStaticText* m_label;
249 wxWindow* m_valueCtrl;
250 wxWindow* m_eventSource;
251 wxStaticText* m_unitLabel;
252
259
261
265
268
270
273
276};
277
278
283{
284public:
286
288
289 void SetControl( wxWindow* aControl );
290};
291
292#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:283
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:275
wxString getTextForValue(long long int aValue) const
int GetIntValue()
Definition: unit_binder.h:134
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:263
wxString getTextForDoubleValue(double aValue) const
const EDA_IU_SCALE * m_iuScale
Currently used units.
Definition: unit_binder.h:254
wxString m_errorMessage
Definition: unit_binder.h:260
virtual EDA_ANGLE GetAngleValue()
bool m_negativeZero
Indicates "-0" should be displayed for 0.
Definition: unit_binder.h:256
int m_precision
0 to 6.
Definition: unit_binder.h:258
wxStaticText * m_unitLabel
Can be nullptr.
Definition: unit_binder.h:251
virtual void SetNegativeZero()
Definition: unit_binder.h:78
bool m_unitsInValue
Units label should be included in value text.
Definition: unit_binder.h:269
wxWindow * m_valueCtrl
Definition: unit_binder.h:249
wxWindow * m_eventSource
Definition: unit_binder.h:250
void onSetFocus(wxFocusEvent &aEvent)
void onComboBox(wxCommandEvent &aEvent)
wxStaticText * m_label
The bound widgets.
Definition: unit_binder.h:248
ORIGIN_TRANSFORMS & m_originTransforms
A reference to an ORIGIN_TRANSFORMS object.
Definition: unit_binder.h:272
bool m_bindFocusEvent
Definition: unit_binder.h:245
long m_selStart
Selection start and end of the original text.
Definition: unit_binder.h:266
virtual void SetDoubleOptionsList(std::span< const double > aOptions)
EDA_UNITS m_units
Definition: unit_binder.h:255
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:264
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:213
void delayedFocusHandler(wxCommandEvent &aEvent)
EDA_DATA_TYPE m_dataType
Definition: unit_binder.h:257
ORIGIN_TRANSFORMS::COORD_TYPES_T GetCoordType() const
Get the origin transforms coordinate type.
Definition: unit_binder.h:197
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 SetNull()
virtual ~UNIT_BINDER() override
bool UnitsInvariant() const
Definition: unit_binder.h:73
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:262
void SetCoordType(ORIGIN_TRANSFORMS::COORD_TYPES_T aCoordType)
Set the current origin transform mode.
Definition: unit_binder.h:205
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:48