KiCad PCB EDA Suite
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
133 virtual double GetDoubleValue();
134
135 virtual EDA_ANGLE GetAngleValue();
136
141 bool IsIndeterminate() const;
142
147 wxString GetOriginalText() const;
148
157 virtual bool Validate( double aMin, double aMax, EDA_UNITS aUnits = EDA_UNITS::UNSCALED );
158
159 void SetLabel( const wxString& aLabel );
160
164 void Enable( bool aEnable );
165
172 void Show( bool aShow, bool aResize = false );
173
180 {
181 return m_coordType;
182 }
183
188 {
189 m_coordType = aCoordType;
190 }
191
196 {
197 m_needsEval = true;
198 }
199
200protected:
201 void init( UNITS_PROVIDER* aProvider );
202 void onClick( wxMouseEvent& aEvent );
203
204 void onSetFocus( wxFocusEvent& aEvent );
205 void onKillFocus( wxFocusEvent& aEvent );
206 void delayedFocusHandler( wxCommandEvent& aEvent );
207
208 void onUnitsChanged( wxCommandEvent& aEvent );
209
221 double setPrecision( double aValue, bool aValueUsesUserUnits );
222
223protected:
224 wxWindow* m_eventSource;
226
228 wxStaticText* m_label;
229 wxWindow* m_valueCtrl;
230 wxStaticText* m_unitLabel;
231
238
240
244
247
249
252
255};
256
257
262{
263public:
265
267
268 void SetControl( wxWindow* aControl );
269};
270
271#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:262
void SetControl(wxWindow *aControl)
PROPERTY_EDITOR_UNIT_BINDER(EDA_DRAW_FRAME *aParent)
ORIGIN_TRANSFORMS::COORD_TYPES_T m_coordType
Type of coordinate for display origin transforms.
Definition: unit_binder.h:254
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:242
const EDA_IU_SCALE * m_iuScale
Definition: unit_binder.h:233
wxString m_errorMessage
Definition: unit_binder.h:239
virtual EDA_ANGLE GetAngleValue()
bool m_negativeZero
Indicates "-0" should be displayed for 0.
Definition: unit_binder.h:235
int m_precision
0 to 6
Definition: unit_binder.h:237
wxStaticText * m_unitLabel
Can be nullptr.
Definition: unit_binder.h:230
virtual void SetNegativeZero()
Definition: unit_binder.h:71
bool m_unitsInValue
Units label should be included in value text.
Definition: unit_binder.h:248
wxWindow * m_valueCtrl
Definition: unit_binder.h:229
wxWindow * m_eventSource
Definition: unit_binder.h:224
void onSetFocus(wxFocusEvent &aEvent)
UNIT_BINDER(EDA_DRAW_FRAME *aParent, wxStaticText *aLabel, wxWindow *aValueCtrl, wxStaticText *aUnitLabel, bool aAllowEval=true, bool aBindFocusEvent=true)
Definition: unit_binder.cpp:39
wxStaticText * m_label
Definition: unit_binder.h:228
ORIGIN_TRANSFORMS & m_originTransforms
A reference to an ORIGIN_TRANSFORMS object.
Definition: unit_binder.h:251
bool m_bindFocusEvent
The bound widgets.
Definition: unit_binder.h:225
long m_selStart
Selection start and end of the original text.
Definition: unit_binder.h:245
EDA_UNITS m_units
Definition: unit_binder.h:234
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:243
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:195
void delayedFocusHandler(wxCommandEvent &aEvent)
EDA_DATA_TYPE m_dataType
Definition: unit_binder.h:236
ORIGIN_TRANSFORMS::COORD_TYPES_T GetCoordType() const
Get the origin transforms coordinate type.
Definition: unit_binder.h:179
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:241
void SetCoordType(ORIGIN_TRANSFORMS::COORD_TYPES_T aCoordType)
Set the current origin transform mode.
Definition: unit_binder.h:187
void onUnitsChanged(wxCommandEvent &aEvent)
EDA_DATA_TYPE
The type of unit.
Definition: eda_units.h:36
EDA_UNITS
Definition: eda_units.h:43