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 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 <eda_item.h>
32 #include <origin_transforms.h>
34 
35 
36 class wxTextEntry;
37 class wxSpinButton;
38 class wxStaticText;
39 
40 
41 class UNIT_BINDER : public wxEvtHandler
42 {
43 public:
44 
56  UNIT_BINDER( EDA_DRAW_FRAME* aParent,
57  wxStaticText* aLabel, wxWindow* aValueCtrl, wxStaticText* aUnitLabel,
58  bool aAllowEval = true );
59 
60  ~UNIT_BINDER() override;
61 
66  virtual void SetUnits( EDA_UNITS aUnits );
67 
75  virtual void SetPrecision( int aLength );
76 
81  void SetDataType( EDA_DATA_TYPE aDataType );
82 
88  virtual void SetValue( int aValue );
89 
90  void SetValue( wxString aValue );
91 
99  virtual void SetDoubleValue( double aValue );
100 
107  virtual void ChangeValue( int aValue );
108 
109  void ChangeValue( const wxString& aValue );
110 
115  virtual long long int GetValue();
116 
123  virtual double GetDoubleValue();
124 
130  bool IsIndeterminate() const;
131 
137  wxString GetOriginalText() const;
138 
148  virtual bool Validate( double aMin, double aMax, EDA_UNITS aUnits = EDA_UNITS::UNSCALED );
149 
150  void SetLabel( const wxString& aLabel );
151 
156  void Enable( bool aEnable );
157 
165  void Show( bool aShow, bool aResize = false );
166 
173  {
174  return m_coordType;
175  }
176 
182  {
183  m_coordType = aCoordType;
184  }
185 
186 protected:
187 
188  void onSetFocus( wxFocusEvent& aEvent );
189  void onKillFocus( wxFocusEvent& aEvent );
190  void delayedFocusHandler( wxCommandEvent& aEvent );
191 
192  void onUnitsChanged( wxCommandEvent& aEvent );
193 
203  double setPrecision( double aValue, bool aValueUsesUserUnits );
204 
206 
208  wxStaticText* m_label;
209  wxWindow* m_valueCtrl;
210  wxStaticText* m_unitLabel; // Can be nullptr
211 
215  int m_precision; // 0 to 6
216 
218  wxString m_errorMessage;
219 
224 
227  long m_selEnd;
228 
231 
234 };
235 
236 #endif /* __UNIT_BINDER_H_ */
wxString m_errorMessage
Validation support.
Definition: unit_binder.h:218
wxString GetOriginalText() const
Function GetOriginalText Returns the pre-evaluated text (or the current text if evaluation is not sup...
ORIGIN_TRANSFORMS::COORD_TYPES_T m_coordType
Type of coordinate for display origin transforms.
Definition: unit_binder.h:233
EDA_DRAW_FRAME * m_frame
Definition: unit_binder.h:205
~UNIT_BINDER() override
Definition: unit_binder.cpp:75
UNIT_BINDER(EDA_DRAW_FRAME *aParent, wxStaticText *aLabel, wxWindow *aValueCtrl, wxStaticText *aUnitLabel, bool aAllowEval=true)
Constructor.
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:230
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
Definition: unit_binder.h:223
bool IsIndeterminate() const
Function IsIndeterminate Returns true if the control holds the indeterminate value (for instance,...
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:213
void Show(bool aShow, bool aResize=false)
Function Show Shows/hides the label, widget and units label.
wxStaticText * m_label
The bound widgets
Definition: unit_binder.h:208
EDA_DATA_TYPE m_dataType
Definition: unit_binder.h:214
wxStaticText * m_unitLabel
Definition: unit_binder.h:210
NUMERIC_EVALUATOR m_eval
Evaluator
Definition: unit_binder.h:221
wxWindow * m_valueCtrl
Definition: unit_binder.h:209
ORIGIN_TRANSFORMS::COORD_TYPES_T GetCoordType() const
Get the origin transforms coordinate type.
Definition: unit_binder.h:172
bool m_allowEval
Definition: unit_binder.h:222
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)
Function Validate Validates the control against the given range, informing the user of any errors fou...
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)
Function SetValue Sets new value (in Internal Units) for the text field, taking care of units convers...
virtual long long int GetValue()
Function GetValue Returns the current value in Internal Units.
long m_selStart
Selection start and end of the original text
Definition: unit_binder.h:226
void SetCoordType(ORIGIN_TRANSFORMS::COORD_TYPES_T aCoordType)
Function SetOriginTransform Sets the current origin transform mode.
Definition: unit_binder.h:181
virtual void SetDoubleValue(double aValue)
Function SetDoubleValue Sets new value (in Internal Units) for the text field, taking care of units c...
virtual double GetDoubleValue()
Function GetValue Returns 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)
Function Enable Enables/diasables the label, widget and units label.
virtual void ChangeValue(int aValue)
Function ChangeValue Changes the value (in Internal Units) for the text field, taking care of units c...