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  * Author: Maciej Suminski <maciej.suminski@cern.ch>
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 #ifndef __UNIT_BINDER_H_
26 #define __UNIT_BINDER_H_
27 
28 #include <common.h>
29 #include <base_units.h>
30 #include <base_struct.h>
32 
33 
34 class wxTextEntry;
35 class wxSpinButton;
36 class wxStaticText;
37 
38 
39 class UNIT_BINDER : public wxEvtHandler
40 {
41 public:
42 
54  UNIT_BINDER( EDA_DRAW_FRAME* aParent,
55  wxStaticText* aLabel, wxWindow* aValue, wxStaticText* aUnitLabel,
56  bool aUseMils = false, bool aAllowEval = true );
57 
63  virtual void SetUnits( EDA_UNITS aUnits, bool aUseMils = false );
64 
70  virtual void SetValue( int aValue );
71 
72  void SetValue( wxString aValue );
73 
79  virtual void SetDoubleValue( double aValue );
80 
87  virtual void ChangeValue( int aValue );
88 
89  void ChangeValue( wxString aValue );
90 
95  virtual long long int GetValue();
96 
101  virtual double GetDoubleValue();
102 
108  bool IsIndeterminate() const;
109 
118  virtual bool Validate( long long int aMin, long long int aMax, bool setFocusOnError = true );
119 
120  void SetLabel( const wxString& aLabel );
121 
126  void Enable( bool aEnable );
127 
135  void Show( bool aShow, bool aResize = false );
136 
137 protected:
138 
139  void onSetFocus( wxFocusEvent& aEvent );
140  void onKillFocus( wxFocusEvent& aEvent );
141  void delayedFocusHandler( wxCommandEvent& aEvent );
142 
144  wxStaticText* m_label;
145  wxWindow* m_value;
146  wxStaticText* m_unitLabel;
147 
150  bool m_useMils;
151 
153  wxString m_errorMessage;
154 
159 
162  long m_selEnd;
163 };
164 
165 #endif /* __UNIT_BINDER_H_ */
EDA_UNITS
Definition: common.h:184
wxString m_errorMessage
Validation support.
Definition: unit_binder.h:153
void delayedFocusHandler(wxCommandEvent &aEvent)
wxWindow * m_value
Definition: unit_binder.h:145
Implementation of conversion functions that require both schematic and board internal units.
bool m_needsEval
Definition: unit_binder.h:158
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:149
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:144
UNIT_BINDER(EDA_DRAW_FRAME *aParent, wxStaticText *aLabel, wxWindow *aValue, wxStaticText *aUnitLabel, bool aUseMils=false, bool aAllowEval=true)
Constructor.
Definition: unit_binder.cpp:37
wxStaticText * m_unitLabel
Definition: unit_binder.h:146
NUMERIC_EVALUATOR m_eval
Evaluator
Definition: unit_binder.h:156
bool m_useMils
Definition: unit_binder.h:150
virtual bool Validate(long long int aMin, long long int aMax, bool setFocusOnError=true)
Function Validate Validates the control against the given range, informing the user of any errors fou...
bool m_allowEval
Definition: unit_binder.h:157
void onKillFocus(wxFocusEvent &aEvent)
Definition: unit_binder.cpp:97
void onSetFocus(wxFocusEvent &aEvent)
Definition: unit_binder.cpp:76
void SetLabel(const wxString &aLabel)
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:161
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:68
virtual void ChangeValue(int aValue)
Function ChangeValue Changes the value (in Internal Units) for the text field, taking care of units c...