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 
74  virtual void SetPrecision( int aLength );
75 
80  void SetDataType( EDA_DATA_TYPE aDataType );
81 
87  virtual void SetValue( int aValue );
88 
89  void SetValue( wxString aValue );
90 
98  virtual void SetDoubleValue( double aValue );
99 
106  virtual void ChangeValue( int aValue );
107 
108  void ChangeValue( const wxString& aValue );
109 
113  virtual long long int GetValue();
114 
121  virtual double GetDoubleValue();
122 
127  bool IsIndeterminate() const;
128 
133  wxString GetOriginalText() const;
134 
143  virtual bool Validate( double aMin, double aMax, EDA_UNITS aUnits = EDA_UNITS::UNSCALED );
144 
145  void SetLabel( const wxString& aLabel );
146 
150  void Enable( bool aEnable );
151 
158  void Show( bool aShow, bool aResize = false );
159 
166  {
167  return m_coordType;
168  }
169 
174  {
175  m_coordType = aCoordType;
176  }
177 
178 protected:
179 
180  void onSetFocus( wxFocusEvent& aEvent );
181  void onKillFocus( wxFocusEvent& aEvent );
182  void delayedFocusHandler( wxCommandEvent& aEvent );
183 
184  void onUnitsChanged( wxCommandEvent& aEvent );
185 
197  double setPrecision( double aValue, bool aValueUsesUserUnits );
198 
200 
202  wxStaticText* m_label;
203  wxWindow* m_valueCtrl;
204  wxStaticText* m_unitLabel; // Can be nullptr
205 
209  int m_precision; // 0 to 6
210 
212  wxString m_errorMessage;
213 
218 
221  long m_selEnd;
222 
225 
228 };
229 
230 #endif /* __UNIT_BINDER_H_ */
wxString m_errorMessage
< Validation support.
Definition: unit_binder.h:212
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:227
EDA_DRAW_FRAME * m_frame
The bound widgets.
Definition: unit_binder.h:199
~UNIT_BINDER() override
Definition: unit_binder.cpp:75
UNIT_BINDER(EDA_DRAW_FRAME *aParent, wxStaticText *aLabel, wxWindow *aValueCtrl, wxStaticText *aUnitLabel, bool aAllowEval=true)
Definition: unit_binder.cpp:38
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:224
void SetDataType(EDA_DATA_TYPE aDataType)
Used to override the datatype of the displayed property (default is DISTANCE)
Definition: unit_binder.cpp:96
bool m_needsEval
Selection start and end of the original text.
Definition: unit_binder.h:217
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 (...
Definition: unit_binder.cpp:90
EDA_UNITS m_units
< Currently used units.
Definition: unit_binder.h:207
void Show(bool aShow, bool aResize=false)
Show/hide the label, widget and units label.
wxStaticText * m_label
Definition: unit_binder.h:202
EDA_DATA_TYPE m_dataType
Definition: unit_binder.h:208
wxStaticText * m_unitLabel
Definition: unit_binder.h:204
NUMERIC_EVALUATOR m_eval
Definition: unit_binder.h:215
wxWindow * m_valueCtrl
Definition: unit_binder.h:203
ORIGIN_TRANSFORMS::COORD_TYPES_T GetCoordType() const
Get the origin transforms coordinate type.
Definition: unit_binder.h:165
bool m_allowEval
Definition: unit_binder.h:216
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:81
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
Definition: unit_binder.h:220
void SetCoordType(ORIGIN_TRANSFORMS::COORD_TYPES_T aCoordType)
Set the current origin transform mode.
Definition: unit_binder.h:173
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)
Change the value (in Internal Units) for the text field, taking care of units conversion but does not...