KiCad PCB EDA Suite
wxwineda.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, jaen-pierre.charras@gipsa-lab.inpg.com
5  * Copyright (C) 1992-2011 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 
29 #include <fctsys.h>
30 #include <wxstruct.h>
31 #include <dialog_helpers.h>
32 #include <base_units.h>
33 #include <macros.h>
34 
35 
36 /*******************************************************/
37 /* Class to edit a graphic + text size in INCHES or MM */
38 /*******************************************************/
40  const wxString& Title,
41  const wxString& TextToEdit,
42  int textsize,
43  EDA_UNITS_T user_unit,
44  wxBoxSizer* BoxSizer,
45  int framelen )
46 {
47  m_UserUnit = user_unit;
48  m_Title = NULL;
49 
50  m_Title = new wxStaticText( parent, -1, Title );
51 
52  BoxSizer->Add( m_Title, 0, wxGROW | wxLEFT | wxRIGHT | wxTOP, 5 );
53 
54  m_FrameText = new wxTextCtrl( parent, -1, TextToEdit );
55 
56  BoxSizer->Add( m_FrameText, 0, wxGROW | wxLEFT | wxRIGHT | wxBOTTOM, 5 );
57 
58  if( !Title.IsEmpty() )
59  {
60  wxString msg;
61  msg.Printf( _( "Size%s" ), GetChars( ReturnUnitSymbol( m_UserUnit ) ) );
62  wxStaticText* text = new wxStaticText( parent, -1, msg );
63 
64  BoxSizer->Add( text, 0, wxGROW | wxLEFT | wxRIGHT, 5 );
65  }
66 
67  wxString value = FormatSize( m_UserUnit, textsize );
68 
69  m_FrameSize = new wxTextCtrl( parent, -1, value, wxDefaultPosition, wxSize( 70, -1 ) );
70 
71  BoxSizer->Add( m_FrameSize, 0, wxGROW | wxLEFT | wxRIGHT | wxBOTTOM, 5 );
72 }
73 
74 
76 {
77  /* no, these are deleted by the BoxSizer
78  delete m_FrameText;
79  delete m_Title;
80  */
81 }
82 
83 
84 wxString EDA_GRAPHIC_TEXT_CTRL::FormatSize( EDA_UNITS_T aUnit, int textSize )
85 {
86  // Limiting the size of the text of reasonable values.
87  if( textSize < 10 )
88  textSize = 10;
89 
90  if( textSize > 3000 )
91  textSize = 3000;
92 
93  return StringFromValue( aUnit, textSize );
94 }
95 
96 
97 void EDA_GRAPHIC_TEXT_CTRL::SetTitle( const wxString& title )
98 {
99  m_Title->SetLabel( title );
100 }
101 
102 
103 void EDA_GRAPHIC_TEXT_CTRL::SetValue( const wxString& value )
104 {
105  m_FrameText->SetValue( value );
106 }
107 
108 
110 {
111  wxString value = FormatSize( m_UserUnit, textSize );
112  m_FrameSize->SetValue( value );
113 }
114 
115 
116 const wxString EDA_GRAPHIC_TEXT_CTRL::GetText() const
117 {
118  wxString text = m_FrameText->GetValue();
119  return text;
120 }
121 
122 
123 int EDA_GRAPHIC_TEXT_CTRL::ParseSize( const wxString& sizeText, EDA_UNITS_T aUnit )
124 {
125  int textsize;
126 
127  textsize = ValueFromString( aUnit, sizeText );
128 
129  // Limit to reasonable size
130  if( textsize < 10 )
131  textsize = 10;
132 
133  if( textsize > 3000 )
134  textsize = 3000;
135 
136  return textsize;
137 }
138 
139 
141 {
142  return ParseSize( m_FrameSize->GetValue(), m_UserUnit );
143 }
144 
145 
147 {
148  m_FrameText->Enable( state );
149 }
150 
151 
152 /********************************************************/
153 /* Class to display and edit a coordinated INCHES or MM */
154 /********************************************************/
156  const wxString& title,
157  const wxPoint& pos_to_edit,
158  EDA_UNITS_T user_unit,
159  wxBoxSizer* BoxSizer )
160 {
161  wxString text;
162 
163  m_UserUnit = user_unit;
164 
165  if( title.IsEmpty() )
166  text = _( "Pos " );
167  else
168  text = title;
169 
170  text += _( "X" ) + ReturnUnitSymbol( m_UserUnit );
171  m_TextX = new wxStaticText( parent, -1, text );
172 
173  BoxSizer->Add( m_TextX, 0, wxGROW | wxLEFT | wxRIGHT | wxTOP, 5 );
174  m_FramePosX = new wxTextCtrl( parent, -1, wxEmptyString, wxDefaultPosition );
175 
176  BoxSizer->Add( m_FramePosX, 0, wxGROW | wxLEFT | wxRIGHT | wxBOTTOM, 5 );
177 
178 
179  if( title.IsEmpty() )
180  text = _( "Pos " );
181  else
182  text = title;
183  text += _( "Y" ) + ReturnUnitSymbol( m_UserUnit );
184 
185  m_TextY = new wxStaticText( parent, -1, text );
186 
187  BoxSizer->Add( m_TextY, 0, wxGROW | wxLEFT | wxRIGHT | wxTOP, 5 );
188 
189  m_FramePosY = new wxTextCtrl( parent, -1, wxEmptyString );
190 
191  BoxSizer->Add( m_FramePosY, 0, wxGROW | wxLEFT | wxRIGHT | wxBOTTOM, 5 );
192 
193  SetValue( pos_to_edit.x, pos_to_edit.y );
194 }
195 
196 
198 {
199  delete m_TextX;
200  delete m_TextY;
201  delete m_FramePosX;
202  delete m_FramePosY;
203 }
204 
205 
206 /* Returns (in internal units) to coordinate between (in user units)
207  */
209 {
210  wxPoint coord;
211 
212  coord.x = ValueFromString( m_UserUnit, m_FramePosX->GetValue() );
213  coord.y = ValueFromString( m_UserUnit, m_FramePosY->GetValue() );
214 
215  return coord;
216 }
217 
218 
219 void EDA_POSITION_CTRL::Enable( bool x_win_on, bool y_win_on )
220 {
221  m_FramePosX->Enable( x_win_on );
222  m_FramePosY->Enable( y_win_on );
223 }
224 
225 
226 void EDA_POSITION_CTRL::SetValue( int x_value, int y_value )
227 {
228  wxString msg;
229 
230  m_Pos_To_Edit.x = x_value;
231  m_Pos_To_Edit.y = y_value;
232 
234  m_FramePosX->Clear();
235  m_FramePosX->SetValue( msg );
236 
238  m_FramePosY->Clear();
239  m_FramePosY->SetValue( msg );
240 }
241 
242 
243 /*******************/
244 /* EDA_SIZE_CTRL */
245 /*******************/
246 EDA_SIZE_CTRL::EDA_SIZE_CTRL( wxWindow* parent, const wxString& title,
247  const wxSize& size_to_edit, EDA_UNITS_T aUnit,
248  wxBoxSizer* aBoxSizer ) :
249  EDA_POSITION_CTRL( parent, title, wxPoint( size_to_edit.x, size_to_edit.y ),
250  aUnit, aBoxSizer )
251 {
252 }
253 
254 
256 {
258  wxSize size;
259 
260  size.x = pos.x;
261  size.y = pos.y;
262  return size;
263 }
264 
265 
266 /**************************************************************/
267 /* Class to display and edit a dimension INCHES, MM, or other */
268 /**************************************************************/
269 EDA_VALUE_CTRL::EDA_VALUE_CTRL( wxWindow* parent, const wxString& title,
270  int value, EDA_UNITS_T user_unit, wxBoxSizer* BoxSizer )
271 {
272  wxString label = title;
273 
274  m_UserUnit = user_unit;
275  m_Value = value;
276  label += ReturnUnitSymbol( m_UserUnit );
277 
278  m_Text = new wxStaticText( parent, -1, label );
279 
280  BoxSizer->Add( m_Text, 0, wxGROW | wxLEFT | wxRIGHT | wxTOP, 5 );
281 
282  wxString stringvalue = StringFromValue( m_UserUnit, m_Value );
283  m_ValueCtrl = new wxTextCtrl( parent, -1, stringvalue );
284 
285  BoxSizer->Add( m_ValueCtrl,
286  0,
287  wxGROW | wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT | wxBOTTOM,
288  5 );
289 }
290 
291 
293 {
294  delete m_ValueCtrl;
295  delete m_Text;
296 }
297 
298 
300 {
301  int coord;
302  wxString txtvalue = m_ValueCtrl->GetValue();
303 
304  coord = ValueFromString( m_UserUnit, txtvalue );
305  return coord;
306 }
307 
308 
309 void EDA_VALUE_CTRL::SetValue( int new_value )
310 {
311  wxString buffer;
312 
313  m_Value = new_value;
314 
315  buffer = StringFromValue( m_UserUnit, m_Value );
316  m_ValueCtrl->SetValue( buffer );
317 }
318 
319 
320 void EDA_VALUE_CTRL::Enable( bool enbl )
321 {
322  m_ValueCtrl->Enable( enbl );
323  m_Text->Enable( enbl );
324 }
EDA_GRAPHIC_TEXT_CTRL(wxWindow *parent, const wxString &Title, const wxString &TextToEdit, int textsize, EDA_UNITS_T user_unit, wxBoxSizer *BoxSizer, int framelen=200)
Definition: wxwineda.cpp:39
wxTextCtrl * m_FrameText
void Enable(bool state)
Definition: wxwineda.cpp:146
Implementation of conversion functions that require both schematic and board internal units...
void Enable(bool x_win_on, bool y_win_on)
Definition: wxwineda.cpp:219
wxPoint GetValue()
Definition: wxwineda.cpp:208
wxString ReturnUnitSymbol(EDA_UNITS_T aUnit, const wxString &formatString)
Returns the units symbol.
Definition: base_units.cpp:420
EDA_UNITS_T m_UserUnit
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
static int ParseSize(const wxString &sizeText, EDA_UNITS_T user_unit)
Definition: wxwineda.cpp:123
void Enable(bool enbl)
Definition: wxwineda.cpp:320
wxStaticText * m_Title
void SetTitle(const wxString &title)
Definition: wxwineda.cpp:97
wxTextCtrl * m_ValueCtrl
This file contains miscellaneous commonly used macros and functions.
const wxString GetText() const
Definition: wxwineda.cpp:116
EDA_POSITION_CTRL(wxWindow *parent, const wxString &title, const wxPoint &pos_to_edit, EDA_UNITS_T user_unit, wxBoxSizer *BoxSizer)
Definition: wxwineda.cpp:155
void SetValue(int new_value)
Definition: wxwineda.cpp:309
wxStaticText * m_TextY
Base window classes and related definitions.
EDA_UNITS_T m_UserUnit
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
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)
Definition: wxwineda.cpp:246
wxSize GetValue()
Definition: wxwineda.cpp:255
void SetValue(const wxString &value)
Definition: wxwineda.cpp:103
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
wxStaticText * m_Text
wxTextCtrl * m_FrameSize
wxTextCtrl * m_FramePosY
EDA_VALUE_CTRL(wxWindow *parent, const wxString &title, int value, EDA_UNITS_T user_unit, wxBoxSizer *BoxSizer)
Definition: wxwineda.cpp:269
wxStaticText * m_TextX
static wxString FormatSize(EDA_UNITS_T user_unit, int textSize)
Function FormatSize formats a string containing the size in the desired units.
Definition: wxwineda.cpp:84
void SetValue(int x_value, int y_value)
Definition: wxwineda.cpp:226
EDA_UNITS_T
Definition: common.h:144