KiCad PCB EDA Suite
wx_unit_binder.cpp
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 #include <wx/stattext.h>
26 #include <wx/sizer.h>
27 #include <wx/textentry.h>
28 #include <limits>
29 #include <base_units.h>
30 #include <wx/valnum.h>
31 
32 #include <boost/optional.hpp>
33 
34 #include "wx_unit_binder.h"
35 
36 WX_UNIT_BINDER::WX_UNIT_BINDER( wxWindow* aParent, wxTextEntry* aTextInput,
37  wxStaticText* aUnitLabel, wxSpinButton* aSpinButton ) :
38  m_textEntry( aTextInput ),
39  m_unitLabel( aUnitLabel ),
40  m_units( g_UserUnit ),
41  m_step( 1 ),
42  m_min( 0 ),
43  m_max( 1 )
44 {
45  // Use the currently selected units
46  m_textEntry->SetValue( wxT( "0" ) );
48 }
49 
50 
52 {
53 }
54 
55 
56 void WX_UNIT_BINDER::SetValue( int aValue )
57 {
58  wxString s = StringFromValue( m_units, aValue, false );
59 
60  m_textEntry->SetValue( s );
61 
63 }
64 
65 
67 {
68  wxString s = m_textEntry->GetValue();
69 
70  return ValueFromString( m_units, s );
71 }
72 
73 
75 {
76  double dummy;
77 
78  return m_textEntry->GetValue().ToDouble( &dummy );
79 }
80 
81 
82 void WX_UNIT_BINDER::Enable( bool aEnable )
83 {
84  wxWindow* wxWin = dynamic_cast<wxWindow*> ( m_textEntry );
85  wxWin->Enable( aEnable );
86  m_unitLabel->Enable( aEnable );
87 }
88 
Implementation of conversion functions that require both schematic and board internal units...
wxString StringFromValue(EDA_UNITS_T aUnit, int aValue, bool aAddUnitSymbol)
Function StringFromValue returns the string from aValue according to units (inch, mm ...
Definition: base_units.cpp:203
EDA_UNITS_T m_units
Currently used units.
wxTextEntry * m_textEntry
Text input control.
bool Valid() const
Function Valid Returns true if the text control contains a real number.
virtual ~WX_UNIT_BINDER()
virtual void SetValue(int aValue)
Function SetValue Sets new value (in Internal Units) for the text field, taking care of units convers...
wxString GetAbbreviatedUnitsLabel(EDA_UNITS_T aUnit)
Definition: base_units.cpp:479
void Enable(bool aEnable)
Function Enable Enables/diasables the binded widgets.
int ValueFromString(EDA_UNITS_T aUnits, const wxString &aTextValue)
Function ValueFromString converts aTextValue in aUnits to internal units used by the application...
Definition: base_units.cpp:368
EDA_UNITS_T g_UserUnit
Global variables definitions.
Definition: common.cpp:56
virtual int GetValue() const
Function GetValue Returns the current value in Internal Units.
static LIB_PART * dummy()
Used when a LIB_PART is not found in library to draw a dummy shape This component is a 400 mils squar...
wxStaticText * m_unitLabel
Label showing currently used units.
WX_UNIT_BINDER(wxWindow *aParent, wxTextEntry *aTextInput, wxStaticText *aUnitLabel, wxSpinButton *aSpinButton=NULL)
Constructor.