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 <base_units.h>
30#include <units_provider.h>
32#include <wx/event.h>
33
34class EDA_BASE_FRAME;
35class EDA_DRAW_FRAME;
36class wxTextEntry;
37class wxSpinButton;
38class wxStaticText;
39
40class UNIT_BINDER : public wxEvtHandler
41{
42public:
43
56 wxStaticText* aLabel, wxWindow* aValueCtrl, wxStaticText* aUnitLabel,
57 bool aAllowEval = true, bool aBindFocusEvent = true );
58
59 UNIT_BINDER( UNITS_PROVIDER* aUnitsProvider, wxWindow* aEventSource,
60 wxStaticText* aLabel, wxWindow* aValueCtrl, wxStaticText* aUnitLabel,
61 bool aAllowEval = true, bool aBindFocusEvent = true );
62
63 virtual ~UNIT_BINDER() override;
64
69 virtual void SetUnits( EDA_UNITS aUnits );
70
71 virtual void SetNegativeZero() { m_negativeZero = true; }
72
80 virtual void SetPrecision( int aLength );
81
86 void SetDataType( EDA_DATA_TYPE aDataType );
87
91 virtual void SetValue( long long int aValue );
92
93 void SetValue( const wxString& aValue );
94
100 virtual void SetDoubleValue( double aValue );
101
102 virtual void SetAngleValue( const EDA_ANGLE& aValue );
103
108 virtual void ChangeValue( int aValue );
109
110 void ChangeValue( const wxString& aValue );
111
118 virtual void ChangeDoubleValue( double aValue );
119
120 virtual void ChangeAngleValue( const EDA_ANGLE& aValue );
121
125 virtual long long int GetValue();
126
127 int GetIntValue() { return (int) GetValue(); }
128
135 virtual double GetDoubleValue();
136
137 virtual EDA_ANGLE GetAngleValue();
138
143 bool IsIndeterminate() const;
144
149 wxString GetOriginalText() const;
150
159 virtual bool Validate( double aMin, double aMax, EDA_UNITS aUnits = EDA_UNITS::UNSCALED );
160
161 void SetLabel( const wxString& aLabel );
162
166 void Enable( bool aEnable );
167
174 void Show( bool aShow, bool aResize = false );
175
182 {
183 return m_coordType;
184 }
185
190 {
191 m_coordType = aCoordType;
192 }
193
198 {
199 m_needsEval = true;
200 }
201
202protected:
203 void init( UNITS_PROVIDER* aProvider );
204 void onClick( wxMouseEvent& aEvent );
205
206 void onSetFocus( wxFocusEvent& aEvent );
207 void onKillFocus( wxFocusEvent& aEvent );
208 void delayedFocusHandler( wxCommandEvent& aEvent );
209
210 void onUnitsChanged( wxCommandEvent& aEvent );
211
223 double setPrecision( double aValue, bool aValueUsesUserUnits );
224
225protected:
227
229 wxStaticText* m_label;
230 wxWindow* m_valueCtrl;
231 wxStaticText* m_unitLabel;
232
239
241
245
248
250
253
256};
257
258
263{
264public:
266
268
269 void SetControl( wxWindow* aControl );
270};
271
272#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:263
void SetControl(wxWindow *aControl)
ORIGIN_TRANSFORMS::COORD_TYPES_T m_coordType
Type of coordinate for display origin transforms.
Definition: unit_binder.h:255
int GetIntValue()
Definition: unit_binder.h:127
virtual void ChangeDoubleValue(double aValue)
Set new value (in Internal Units) for the text field, taking care of units conversion WITHOUT trigger...
wxString GetOriginalText() const
Return the pre-evaluated text (or the current text if evaluation is not supported).
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:243
const EDA_IU_SCALE * m_iuScale
Definition: unit_binder.h:234
wxString m_errorMessage
Definition: unit_binder.h:240
virtual EDA_ANGLE GetAngleValue()
bool m_negativeZero
Indicates "-0" should be displayed for 0.
Definition: unit_binder.h:236
int m_precision
0 to 6
Definition: unit_binder.h:238
wxStaticText * m_unitLabel
Can be nullptr.
Definition: unit_binder.h:231
virtual void SetNegativeZero()
Definition: unit_binder.h:71
bool m_unitsInValue
Units label should be included in value text.
Definition: unit_binder.h:249
wxWindow * m_valueCtrl
Definition: unit_binder.h:230
void onSetFocus(wxFocusEvent &aEvent)
wxStaticText * m_label
Definition: unit_binder.h:229
ORIGIN_TRANSFORMS & m_originTransforms
A reference to an ORIGIN_TRANSFORMS object.
Definition: unit_binder.h:252
bool m_bindFocusEvent
The bound widgets.
Definition: unit_binder.h:226
long m_selStart
Selection start and end of the original text.
Definition: unit_binder.h:246
EDA_UNITS m_units
Definition: unit_binder.h:235
virtual double GetDoubleValue()
Return the current value in Internal Units.
double setPrecision(double aValue, bool aValueUsesUserUnits)
When m_precision > 0 truncate the value aValue to show only m_precision digits in mantissa.
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:244
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:197
void delayedFocusHandler(wxCommandEvent &aEvent)
EDA_DATA_TYPE m_dataType
Definition: unit_binder.h:237
ORIGIN_TRANSFORMS::COORD_TYPES_T GetCoordType() const
Get the origin transforms coordinate type.
Definition: unit_binder.h:181
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:242
void SetCoordType(ORIGIN_TRANSFORMS::COORD_TYPES_T aCoordType)
Set the current origin transform mode.
Definition: unit_binder.h:189
void onUnitsChanged(wxCommandEvent &aEvent)
EDA_DATA_TYPE
The type of unit.
Definition: eda_units.h:37
EDA_UNITS
Definition: eda_units.h:44