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 
56  UNIT_BINDER( EDA_DRAW_FRAME* aParent,
57  wxStaticText* aLabel, wxWindow* aValue, wxStaticText* aUnitLabel,
58  bool aUseMils = false,
59  int aMin = INT_MIN, int aMax = INT_MAX,
60  bool aAllowEval = true );
61 
67  virtual void SetUnits( EDA_UNITS_T aUnits, bool aUseMils = false );
68 
72  void SetMin( int aMin )
73  {
74  wxASSERT( aMin < m_max );
75  m_min = aMin;
76  }
77 
81  void SetMax( int aMax )
82  {
83  wxASSERT( aMax > m_min );
84  m_max = aMax;
85  }
86 
92  virtual void SetValue( int aValue );
93 
94  void SetValue( wxString aValue );
95 
102  virtual void ChangeValue( int aValue );
103 
104  void ChangeValue( wxString aValue );
105 
110  virtual int GetValue();
111 
117  bool IsIndeterminate() const;
118 
126  virtual bool Validate( bool setFocusOnError = false );
127 
128  void SetLabel( const wxString& aLabel );
129 
134  void Enable( bool aEnable );
135 
140  void Show( bool aShow );
141 
142 protected:
143 
144  void onSetFocus( wxFocusEvent& aEvent );
145  void onKillFocus( wxFocusEvent& aEvent );
146  void delayedFocusHandler( wxIdleEvent& aEvent );
147 
149  wxStaticText* m_label;
150  wxWindow* m_value;
151  wxStaticText* m_unitLabel;
152 
155  bool m_useMils;
156 
158  int m_min;
159  int m_max;
160  wxString m_errorMessage;
161 
166 };
167 
168 #endif /* __UNIT_BINDER_H_ */
virtual bool Validate(bool setFocusOnError=false)
Function Validate Validates the control, informing the user of any errors found.
int m_min
Validation support.
Definition: unit_binder.h:158
wxString m_errorMessage
Definition: unit_binder.h:160
wxWindow * m_value
Definition: unit_binder.h:150
Implementation of conversion functions that require both schematic and board internal units...
virtual void SetUnits(EDA_UNITS_T aUnits, bool aUseMils=false)
Function SetUnits Normally not needed (as the UNIT_BINDER inherits from the parent frame)...
Definition: unit_binder.cpp:64
bool m_needsEval
Definition: unit_binder.h:165
The base class for create windows for drawing purpose.
Definition: draw_frame.h:78
virtual int GetValue()
Function GetValue Returns the current value in Internal Units.
void SetMax(int aMax)
Set the maximal accepted value (in Internal Units).
Definition: unit_binder.h:81
void Show(bool aShow)
Function Show Shows/hides the label, widget and units label.
wxStaticText * m_label
The bound widgets
Definition: unit_binder.h:149
void SetMin(int aMin)
Set the minimal accepted value (in Internal Units).
Definition: unit_binder.h:72
wxStaticText * m_unitLabel
Definition: unit_binder.h:151
NUMERIC_EVALUATOR m_eval
Evaluator
Definition: unit_binder.h:163
bool m_useMils
Definition: unit_binder.h:155
bool m_allowEval
Definition: unit_binder.h:164
void onKillFocus(wxFocusEvent &aEvent)
Definition: unit_binder.cpp:90
void onSetFocus(wxFocusEvent &aEvent)
Definition: unit_binder.cpp:72
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...
void delayedFocusHandler(wxIdleEvent &aEvent)
EDA_UNITS_T m_units
Currently used units.
Definition: unit_binder.h:154
The common library.
bool IsIndeterminate() const
Function IsIndeterminate Returns true if the control holds the indeterminate value (for instance...
UNIT_BINDER(EDA_DRAW_FRAME *aParent, wxStaticText *aLabel, wxWindow *aValue, wxStaticText *aUnitLabel, bool aUseMils=false, int aMin=INT_MIN, int aMax=INT_MAX, bool aAllowEval=true)
Constructor.
Definition: unit_binder.cpp:34
Basic classes for most KiCad items.
EDA_UNITS_T
Definition: common.h:159
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...