KiCad PCB EDA Suite
eda_size_ctrl.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) 2004 Jean-Pierre Charras, jp.charras at wanadoo.fr
5  * Copyright (C) 1992-2018 KiCad Developers, see AUTHORS.txt for contributors.
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 #include <fctsys.h>
25 #include <eda_base_frame.h>
26 #include <dialog_helpers.h>
27 #include <base_units.h>
28 #include <macros.h>
29 
30 
31 /********************************************************/
32 /* Class to display and edit a coordinated INCHES or MM */
33 /********************************************************/
34 EDA_POSITION_CTRL::EDA_POSITION_CTRL( wxWindow* parent, const wxString& title, const wxPoint& aPos,
35  EDA_UNITS_T user_unit, wxBoxSizer* BoxSizer )
36 {
37  m_UserUnit = user_unit;
38 
39  m_TextX = new wxStaticText( parent, -1, title + _( " X:" ) );
40  BoxSizer->Add( m_TextX, 0, wxGROW | wxLEFT | wxRIGHT | wxTOP, 5 );
41 
42  m_FramePosX = new wxTextCtrl( parent, -1, wxEmptyString, wxDefaultPosition );
43  BoxSizer->Add( m_FramePosX, 0, wxGROW | wxLEFT | wxRIGHT | wxBOTTOM, 5 );
44 
45  m_TextY = new wxStaticText( parent, -1, title + _( " Y:" ) );
46  BoxSizer->Add( m_TextY, 0, wxGROW | wxLEFT | wxRIGHT | wxTOP, 5 );
47 
48  m_FramePosY = new wxTextCtrl( parent, -1, wxEmptyString );
49  BoxSizer->Add( m_FramePosY, 0, wxGROW | wxLEFT | wxRIGHT | wxBOTTOM, 5 );
50 
51  SetValue( aPos.x, aPos.y );
52 }
53 
54 
56 {
57  delete m_TextX;
58  delete m_TextY;
59  delete m_FramePosX;
60  delete m_FramePosY;
61 }
62 
63 
64 /* Returns (in internal units) to coordinate between (in user units)
65  */
67 {
68  return wxPoint( ValueFromString( m_UserUnit, m_FramePosX->GetValue() ),
69  ValueFromString( m_UserUnit, m_FramePosY->GetValue() ) );
70 }
71 
72 
73 void EDA_POSITION_CTRL::Enable( bool x_win_on, bool y_win_on )
74 {
75  m_FramePosX->Enable( x_win_on );
76  m_FramePosY->Enable( y_win_on );
77 }
78 
79 
80 void EDA_POSITION_CTRL::SetValue( int x_value, int y_value )
81 {
82  m_FramePosX->SetValue( StringFromValue( m_UserUnit, x_value, true ) );
83  m_FramePosY->SetValue( StringFromValue( m_UserUnit, y_value, true ) );
84 }
85 
86 
87 /*******************/
88 /* EDA_SIZE_CTRL */
89 /*******************/
90 EDA_SIZE_CTRL::EDA_SIZE_CTRL( wxWindow* parent, const wxString& title, const wxSize& aSize,
91  EDA_UNITS_T aUnit, wxBoxSizer* aBoxSizer ) :
92  EDA_POSITION_CTRL( parent, title, wxPoint( aSize.x, aSize.y ), aUnit, aBoxSizer )
93 {
94 }
95 
96 
98 {
100 
101  return wxSize( pos.x, pos.y );
102 }
103 
104 
Implementation of conversion functions that require both schematic and board internal units...
void Enable(bool x_win_on, bool y_win_on)
int ValueFromString(EDA_UNITS_T aUnits, const wxString &aTextValue, bool aUseMils)
Function ValueFromString converts aTextValue in aUnits to internal units used by the application...
Definition: base_units.cpp:409
This file contains miscellaneous commonly used macros and functions.
EDA_POSITION_CTRL(wxWindow *parent, const wxString &title, const wxPoint &pos_to_edit, EDA_UNITS_T user_unit, wxBoxSizer *BoxSizer)
wxStaticText * m_TextY
EDA_UNITS_T m_UserUnit
Base window classes and related definitions.
Helper dialog and control classes.
wxTextCtrl * m_FramePosX
EDA_SIZE_CTRL(wxWindow *parent, const wxString &title, const wxSize &size_to_edit, EDA_UNITS_T user_unit, wxBoxSizer *BoxSizer)
wxSize GetValue()
wxTextCtrl * m_FramePosY
wxString StringFromValue(EDA_UNITS_T aUnits, int aValue, bool aAddUnitSymbol, bool aUseMils)
Function StringFromValue returns the string from aValue according to units (inch, mm ...
Definition: base_units.cpp:210
wxStaticText * m_TextX
void SetValue(int x_value, int y_value)
EDA_UNITS_T
Definition: common.h:159