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_T aUnits, bool aUseMils = false );
64 
70  virtual void SetValue( int aValue );
71 
72  void SetValue( wxString aValue );
73 
80  virtual void ChangeValue( int aValue );
81 
82  void ChangeValue( wxString aValue );
83 
88  virtual int GetValue();
89 
95  bool IsIndeterminate() const;
96 
105  virtual bool Validate( int aMin, int aMax, bool setFocusOnError = true );
106 
107  void SetLabel( const wxString& aLabel );
108 
113  void Enable( bool aEnable );
114 
119  void Show( bool aShow );
120 
121 protected:
122 
123  void onSetFocus( wxFocusEvent& aEvent );
124  void onKillFocus( wxFocusEvent& aEvent );
125  void delayedFocusHandler( wxCommandEvent& aEvent );
126 
128  wxStaticText* m_label;
129  wxWindow* m_value;
130  wxStaticText* m_unitLabel;
131 
134  bool m_useMils;
135 
137  wxString m_errorMessage;
138 
143 };
144 
145 #endif /* __UNIT_BINDER_H_ */
wxString m_errorMessage
Validation support.
Definition: unit_binder.h:137
void delayedFocusHandler(wxCommandEvent &aEvent)
wxWindow * m_value
Definition: unit_binder.h:129
Implementation of conversion functions that require both schematic and board internal units.
virtual bool Validate(int aMin, int aMax, bool setFocusOnError=true)
Function Validate Validates the control against the given range, informing the user of any errors fou...
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:65
bool m_needsEval
Definition: unit_binder.h:142
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.
Definition: draw_frame.h:81
virtual int GetValue()
Function GetValue Returns the current value in Internal Units.
void Show(bool aShow)
Function Show Shows/hides the label, widget and units label.
wxStaticText * m_label
The bound widgets
Definition: unit_binder.h:128
UNIT_BINDER(EDA_DRAW_FRAME *aParent, wxStaticText *aLabel, wxWindow *aValue, wxStaticText *aUnitLabel, bool aUseMils=false, bool aAllowEval=true)
Constructor.
Definition: unit_binder.cpp:36
wxStaticText * m_unitLabel
Definition: unit_binder.h:130
NUMERIC_EVALUATOR m_eval
Evaluator
Definition: unit_binder.h:140
bool m_useMils
Definition: unit_binder.h:134
bool m_allowEval
Definition: unit_binder.h:141
void onKillFocus(wxFocusEvent &aEvent)
Definition: unit_binder.cpp:91
void onSetFocus(wxFocusEvent &aEvent)
Definition: unit_binder.cpp:73
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...
EDA_UNITS_T m_units
Currently used units.
Definition: unit_binder.h:133
The common library.
Basic classes for most KiCad items.
EDA_UNITS_T
Definition: common.h:157
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...