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 <common.h>
30 #include <base_units.h>
31 #include <base_struct.h>
33 
34 
35 class wxTextEntry;
36 class wxSpinButton;
37 class wxStaticText;
38 
39 
40 class UNIT_BINDER : public wxEvtHandler
41 {
42 public:
43 
55  UNIT_BINDER( EDA_DRAW_FRAME* aParent,
56  wxStaticText* aLabel, wxWindow* aValue, wxStaticText* aUnitLabel,
57  bool aUseMils = false, bool aAllowEval = true );
58 
59  ~UNIT_BINDER() override;
60 
66  virtual void SetUnits( EDA_UNITS aUnits, bool aUseMils = false );
67 
72  void SetDataType( EDA_DATA_TYPE aDataType );
73 
79  virtual void SetValue( int aValue );
80 
81  void SetValue( wxString aValue );
82 
88  virtual void SetDoubleValue( double aValue );
89 
96  virtual void ChangeValue( int aValue );
97 
98  void ChangeValue( const wxString& aValue );
99 
104  virtual long long int GetValue();
105 
110  virtual double GetDoubleValue();
111 
117  bool IsIndeterminate() const;
118 
124  wxString GetOriginalText() const;
125 
136  virtual bool Validate( double aMin, double aMax, EDA_UNITS aUnits = EDA_UNITS::UNSCALED,
137  bool aUseMils = false );
138 
139  void SetLabel( const wxString& aLabel );
140 
145  void Enable( bool aEnable );
146 
154  void Show( bool aShow, bool aResize = false );
155 
156 protected:
157 
158  void onSetFocus( wxFocusEvent& aEvent );
159  void onKillFocus( wxFocusEvent& aEvent );
160  void delayedFocusHandler( wxCommandEvent& aEvent );
161 
162  void onUnitsChanged( wxCommandEvent& aEvent );
163 
165 
167  wxStaticText* m_label;
168  wxWindow* m_value;
169  wxStaticText* m_unitLabel;
170 
173  bool m_useMils;
175 
177  wxString m_errorMessage;
178 
183 
186  long m_selEnd;
187 };
188 
189 #endif /* __UNIT_BINDER_H_ */
EDA_UNITS
Definition: common.h:198
wxString m_errorMessage
Validation support.
Definition: unit_binder.h:177
wxString GetOriginalText() const
Function GetOriginalText Returns the pre-evaluated text (or the current text if evaluation is not sup...
EDA_DRAW_FRAME * m_frame
Definition: unit_binder.h:164
~UNIT_BINDER() override
Definition: unit_binder.cpp:73
void delayedFocusHandler(wxCommandEvent &aEvent)
wxWindow * m_value
Definition: unit_binder.h:168
Implementation of conversion functions that require both schematic and board internal units.
EDA_DATA_TYPE
The type of unit.
Definition: common.h:191
void SetDataType(EDA_DATA_TYPE aDataType)
Used to override the datatype of the displayed property (default is DISTANCE)
Definition: unit_binder.cpp:87
bool m_needsEval
Definition: unit_binder.h:182
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.
EDA_UNITS m_units
Currently used units.
Definition: unit_binder.h:172
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:167
UNIT_BINDER(EDA_DRAW_FRAME *aParent, wxStaticText *aLabel, wxWindow *aValue, wxStaticText *aUnitLabel, bool aUseMils=false, bool aAllowEval=true)
Constructor.
Definition: unit_binder.cpp:38
EDA_DATA_TYPE m_dataType
Definition: unit_binder.h:174
wxStaticText * m_unitLabel
Definition: unit_binder.h:169
NUMERIC_EVALUATOR m_eval
Evaluator
Definition: unit_binder.h:180
bool m_useMils
Definition: unit_binder.h:173
bool m_allowEval
Definition: unit_binder.h:181
virtual bool Validate(double aMin, double aMax, EDA_UNITS aUnits=EDA_UNITS::UNSCALED, bool aUseMils=false)
Function Validate Validates the control against the given range, informing the user of any errors fou...
void onKillFocus(wxFocusEvent &aEvent)
void onSetFocus(wxFocusEvent &aEvent)
void SetLabel(const wxString &aLabel)
void onUnitsChanged(wxCommandEvent &aEvent)
Definition: unit_binder.cpp:94
virtual void SetValue(int aValue)
Function SetValue Sets new value (in Internal Units) for the text field, taking care of units convers...
The common library.
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:185
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.
void Enable(bool aEnable)
Function Enable Enables/diasables the label, widget and units label.
virtual void SetUnits(EDA_UNITS aUnits, bool aUseMils=false)
Function SetUnits Normally not needed (as the UNIT_BINDER inherits from the parent frame),...
Definition: unit_binder.cpp:79
virtual void ChangeValue(int aValue)
Function ChangeValue Changes the value (in Internal Units) for the text field, taking care of units c...