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 (C) 2020-2021 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
169 virtual bool Validate( double aMin, double aMax, EDA_UNITS aUnits = EDA_UNITS::UNSCALED );
170
171 void SetLabel( const wxString& aLabel );
172
176 void Enable( bool aEnable );
177
184 void Show( bool aShow, bool aResize = false );
185
192 {
193 return m_coordType;
194 }
195
200 {
201 m_coordType = aCoordType;
202 }
203
208 {
209 m_needsEval = true;
210 }
211
212protected:
213 void init( UNITS_PROVIDER* aProvider );
214 void onClick( wxMouseEvent& aEvent );
215 void onComboBox( wxCommandEvent& aEvent );
216
217 void onSetFocus( wxFocusEvent& aEvent );
218 void onKillFocus( wxFocusEvent& aEvent );
219 void delayedFocusHandler( wxCommandEvent& aEvent );
220
221 void onUnitsChanged( wxCommandEvent& aEvent );
222
234 double setPrecision( double aValue, bool aValueUsesUserUnits ) const;
235
236 wxString getTextForValue( long long int aValue ) const;
237 wxString getTextForDoubleValue( double aValue ) const;
238
239protected:
241
243 wxStaticText* m_label;
244 wxWindow* m_valueCtrl;
245 wxStaticText* m_unitLabel;
246
253
255
259
262
264
267
270};
271
272
277{
278public:
280
282
283 void SetControl( wxWindow* aControl );
284};
285
286#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:277
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:269
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:257
wxString getTextForDoubleValue(double aValue) const
const EDA_IU_SCALE * m_iuScale
Definition: unit_binder.h:248
wxString m_errorMessage
Definition: unit_binder.h:254
virtual EDA_ANGLE GetAngleValue()
bool m_negativeZero
Indicates "-0" should be displayed for 0.
Definition: unit_binder.h:250
int m_precision
0 to 6
Definition: unit_binder.h:252
wxStaticText * m_unitLabel
Can be nullptr.
Definition: unit_binder.h:245
virtual void SetNegativeZero()
Definition: unit_binder.h:73
bool m_unitsInValue
Units label should be included in value text.
Definition: unit_binder.h:263
wxWindow * m_valueCtrl
Definition: unit_binder.h:244
void onSetFocus(wxFocusEvent &aEvent)
void onComboBox(wxCommandEvent &aEvent)
wxStaticText * m_label
Definition: unit_binder.h:243
ORIGIN_TRANSFORMS & m_originTransforms
A reference to an ORIGIN_TRANSFORMS object.
Definition: unit_binder.h:266
bool m_bindFocusEvent
The bound widgets.
Definition: unit_binder.h:240
long m_selStart
Selection start and end of the original text.
Definition: unit_binder.h:260
virtual void SetDoubleOptionsList(std::span< const double > aOptions)
EDA_UNITS m_units
Definition: unit_binder.h:249
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:258
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:207
void delayedFocusHandler(wxCommandEvent &aEvent)
EDA_DATA_TYPE m_dataType
Definition: unit_binder.h:251
ORIGIN_TRANSFORMS::COORD_TYPES_T GetCoordType() const
Get the origin transforms coordinate type.
Definition: unit_binder.h:191
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.
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:256
void SetCoordType(ORIGIN_TRANSFORMS::COORD_TYPES_T aCoordType)
Set the current origin transform mode.
Definition: unit_binder.h:199
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