~pierre-parent-k/kicad/length-tunning

« back to all changes in this revision

Viewing changes to include/wxunittext.h

  • Committer: Pierre Parent
  • Date: 2014-07-06 10:32:13 UTC
  • mfrom: (4798.1.179 kicad)
  • Revision ID: pierre.parent@insa-rouen.fr-20140706103213-wjsdy0hc9q6wbz5v
Merge with lp:kicad 4977

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * This program source code file is part of KiCad, a free EDA CAD application.
 
3
 *
 
4
 * Copyright (C) 2014  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 WXUNITTEXT_H_
 
26
#define WXUNITTEXT_H_
 
27
 
 
28
#include <common.h>
 
29
#include <wx/spinbutt.h>
 
30
 
 
31
namespace boost
 
32
{
 
33
    template <class T>
 
34
    class optional;
 
35
}
 
36
class wxTextCtrl;
 
37
class wxSpinButton;
 
38
class wxStaticText;
 
39
 
 
40
class WX_UNIT_TEXT : public wxPanel
 
41
{
 
42
public:
 
43
    /**
 
44
     * Constructor.
 
45
     * @param aParent is the parent window.
 
46
     * @param aLabel is the label displayed next to the text input control.
 
47
     * @param aValue is the initial value for the control.
 
48
     * @param aStep is the step size when using spin buttons.
 
49
     */
 
50
    WX_UNIT_TEXT( wxWindow* aParent, const wxString& aLabel = _( "Size:" ),
 
51
                  double aValue = 0.0, double aStep = 0.1 );
 
52
 
 
53
    virtual ~WX_UNIT_TEXT();
 
54
 
 
55
    /**
 
56
     * Function SetUnits
 
57
     * Changes the units used by the control.
 
58
     * @param aUnits is the new unit to be used.
 
59
     * @param aConvert decides if the current value should be converted to the value in new units
 
60
     * or should it stay the same.
 
61
     */
 
62
    void SetUnits( EDA_UNITS_T aUnits, bool aConvert = false );
 
63
 
 
64
    /**
 
65
     * Function SetValue
 
66
     * Sets new value for the control.
 
67
     * @param aValue is the new value.
 
68
     */
 
69
    virtual void SetValue( double aValue );
 
70
 
 
71
    /**
 
72
     * Function GetValue
 
73
     * Returns the current value using specified units (if currently used units are different, then
 
74
     * they are converted first).
 
75
     * @param aUnits is the wanted unit.
 
76
     */
 
77
    //virtual double GetValue( EDA_UNITS_T aUnits ) const;
 
78
 
 
79
    /**
 
80
     * Function GetValue
 
81
     * Returns the current value in currently used units.
 
82
     */
 
83
    virtual boost::optional<double> GetValue() const;
 
84
 
 
85
    /**
 
86
     * Function GetUnits
 
87
     * Returns currently used units.
 
88
     */
 
89
    EDA_UNITS_T GetUnits() const
 
90
    {
 
91
        return m_units;
 
92
    }
 
93
 
 
94
    /**
 
95
     * Function SetStep
 
96
     * Sets the difference introduced by a single spin button click.
 
97
     * @param aStep is new step size.
 
98
     */
 
99
    void SetStep( double aStep )
 
100
    {
 
101
        assert( aStep > 0.0 );
 
102
 
 
103
        m_step = aStep;
 
104
    }
 
105
 
 
106
    /**
 
107
     * Function GetStep
 
108
     * Returns the difference introduced by a single spin button click.
 
109
     */
 
110
    double GetStep() const
 
111
    {
 
112
        return m_step;
 
113
    }
 
114
 
 
115
protected:
 
116
    ///> Spin up button click event handler.
 
117
    void onSpinUpEvent( wxSpinEvent& aEvent );
 
118
 
 
119
    ///> Spin down button click event handler.
 
120
    void onSpinDownEvent( wxSpinEvent& aEvent );
 
121
 
 
122
    ///> Label for the input (e.g. "Size:")
 
123
    wxStaticText*   m_inputLabel;
 
124
 
 
125
    ///> Text input control.
 
126
    wxTextCtrl*     m_inputValue;
 
127
 
 
128
    ///> Spin buttons for changing the value using mouse.
 
129
    wxSpinButton*   m_spinButton;
 
130
 
 
131
    ///> Label showing currently used units.
 
132
    wxStaticText*   m_unitLabel;
 
133
 
 
134
    ///> Currently used units.
 
135
    EDA_UNITS_T     m_units;
 
136
 
 
137
    ///> Step size (added/subtracted difference if spin buttons are used).
 
138
    double          m_step;
 
139
 
 
140
    ///> Default value (or non-specified)
 
141
    static const wxString DEFAULT_VALUE;
 
142
};
 
143
 
 
144
#endif /* WXUNITTEXT_H_ */