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 <maciej.suminski@cern.ch>
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 <eda_units.h>
30 #include <base_units.h>
31 #include <origin_transforms.h>
33 #include <wx/event.h>
34 
35 class EDA_DRAW_FRAME;
36 class wxTextEntry;
37 class wxSpinButton;
38 class wxStaticText;
39 
40 
41 class UNIT_BINDER : public wxEvtHandler
42 {
43 public:
44 
55  UNIT_BINDER( EDA_DRAW_FRAME* aParent,
56  wxStaticText* aLabel, wxWindow* aValueCtrl, wxStaticText* aUnitLabel,
57  bool aAllowEval = true );
58 
59  ~UNIT_BINDER() override;
60 
65  virtual void SetUnits( EDA_UNITS aUnits );
66 
67  virtual void SetNegativeZero() { m_negativeZero = true; }
68 
76  virtual void SetPrecision( int aLength );
77 
82  void SetDataType( EDA_DATA_TYPE aDataType );
83 
87  virtual void SetValue( int aValue );
88 
89  void SetValue( const wxString& aValue );
90 
96  virtual void SetDoubleValue( double aValue );
97 
102  virtual void ChangeValue( int aValue );
103 
104  void ChangeValue( const wxString& aValue );
105 
112  virtual void ChangeDoubleValue( double aValue );
113 
117  virtual long long int GetValue();
118 
125  virtual double GetDoubleValue();
126 
131  bool IsIndeterminate() const;
132 
137  wxString GetOriginalText() const;
138 
147  virtual bool Validate( double aMin, double aMax, EDA_UNITS aUnits = EDA_UNITS::UNSCALED );
148 
149  void SetLabel( const wxString& aLabel );
150 
154  void Enable( bool aEnable );
155 
162  void Show( bool aShow, bool aResize = false );
163 
170  {
171  return m_coordType;
172  }
173 
178  {
179  m_coordType = aCoordType;
180  }
181 
182 protected:
183 
184  void onSetFocus( wxFocusEvent& aEvent );
185  void onKillFocus( wxFocusEvent& aEvent );
186  void delayedFocusHandler( wxCommandEvent& aEvent );
187 
188  void onUnitsChanged( wxCommandEvent& aEvent );
189 
201  double setPrecision( double aValue, bool aValueUsesUserUnits );
202 
204 
206  wxStaticText* m_label;
207  wxWindow* m_valueCtrl;
208  wxStaticText* m_unitLabel;
209 
215 
216  wxString m_errorMessage;
217 
221 
222  long m_selStart;
223  long m_selEnd;
224 
227 
230 };
231 
232 #endif /* __UNIT_BINDER_H_ */
wxString m_errorMessage
Definition: unit_binder.h:216
wxString GetOriginalText() const
Return the pre-evaluated text (or the current text if evaluation is not supported).
ORIGIN_TRANSFORMS::COORD_TYPES_T m_coordType
Type of coordinate for display origin transforms.
Definition: unit_binder.h:229
EDA_DRAW_FRAME * m_frame
The bound widgets.
Definition: unit_binder.h:203
virtual void SetNegativeZero()
Definition: unit_binder.h:67
~UNIT_BINDER() override
Definition: unit_binder.cpp:85
UNIT_BINDER(EDA_DRAW_FRAME *aParent, wxStaticText *aLabel, wxWindow *aValueCtrl, wxStaticText *aUnitLabel, bool aAllowEval=true)
Definition: unit_binder.cpp:40
void delayedFocusHandler(wxCommandEvent &aEvent)
Implementation of conversion functions that require both schematic and board internal units.
EDA_DATA_TYPE
The type of unit.
Definition: eda_units.h:31
ORIGIN_TRANSFORMS & m_originTransforms
A reference to an ORIGIN_TRANSFORMS object.
Definition: unit_binder.h:226
virtual void ChangeDoubleValue(double aValue)
Set new value (in Internal Units) for the text field, taking care of units conversion WITHOUT trigger...
void SetDataType(EDA_DATA_TYPE aDataType)
Used to override the datatype of the displayed property (default is DISTANCE)
bool m_needsEval
Definition: unit_binder.h:220
bool IsIndeterminate() const
Return true if the control holds the indeterminate value (for instance, if it represents a multiple s...
The base class for create windows for drawing purpose.
virtual void SetPrecision(int aLength)
Normally not needed, but can be used to set the precision when using internal units that are floats (...
EDA_UNITS m_units
Definition: unit_binder.h:211
void Show(bool aShow, bool aResize=false)
Show/hide the label, widget and units label.
wxStaticText * m_label
Definition: unit_binder.h:206
EDA_DATA_TYPE m_dataType
Definition: unit_binder.h:213
wxStaticText * m_unitLabel
Can be nullptr.
Definition: unit_binder.h:208
NUMERIC_EVALUATOR m_eval
Definition: unit_binder.h:218
wxWindow * m_valueCtrl
Definition: unit_binder.h:207
bool m_negativeZero
Indicates "-0" should be displayed for 0.
Definition: unit_binder.h:212
ORIGIN_TRANSFORMS::COORD_TYPES_T GetCoordType() const
Get the origin transforms coordinate type.
Definition: unit_binder.h:169
int m_precision
0 to 6
Definition: unit_binder.h:214
bool m_allowEval
Definition: unit_binder.h:219
EDA_UNITS
Definition: eda_units.h:38
COORD_TYPES_T
The supported Display Origin Transform types.
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...
Definition: unit_binder.cpp:92
void onKillFocus(wxFocusEvent &aEvent)
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.
void onSetFocus(wxFocusEvent &aEvent)
void SetLabel(const wxString &aLabel)
A class to perform either relative or absolute display origin transforms for a single axis of a point...
void onUnitsChanged(wxCommandEvent &aEvent)
virtual void SetValue(int aValue)
Set new value (in Internal Units) for the text field, taking care of units conversion.
virtual long long int GetValue()
Return the current value in Internal Units.
long m_selStart
Selection start and end of the original text.
Definition: unit_binder.h:222
void SetCoordType(ORIGIN_TRANSFORMS::COORD_TYPES_T aCoordType)
Set the current origin transform mode.
Definition: unit_binder.h:177
virtual void SetDoubleValue(double aValue)
Set new value (in Internal Units) for the text field, taking care of units conversion.
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.
void Enable(bool aEnable)
Enable/disable the label, widget and units label.
virtual void ChangeValue(int aValue)
Set new value (in Internal Units) for the text field, taking care of units conversion WITHOUT trigger...