wxwineda.cpp 8.45 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
/*
 * This program source code file is part of KiCad, a free EDA CAD application.
 *
 * Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
 * Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, you may find one here:
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * or you may search the http://www.gnu.org website for the version 2 license,
 * or you may write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 */

25 26 27
/**
 * @file wxwineda.cpp
 */
28

29 30 31
#include <fctsys.h>
#include <wxstruct.h>
#include <dialog_helpers.h>
32
#include <base_units.h>
33
#include <macros.h>
34 35


36 37 38
/*******************************************************/
/* Class to edit a graphic + text size in INCHES or MM */
/*******************************************************/
39 40 41 42 43 44
EDA_GRAPHIC_TEXT_CTRL::EDA_GRAPHIC_TEXT_CTRL( wxWindow*       parent,
                                              const wxString& Title,
                                              const wxString& TextToEdit,
                                              int             textsize,
                                              EDA_UNITS_T     user_unit,
                                              wxBoxSizer*     BoxSizer,
45
                                              int             framelen )
46
{
47
    m_UserUnit = user_unit;
48 49 50 51
    m_Title = NULL;

    m_Title = new wxStaticText( parent, -1, Title );

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 59
    if( !Title.IsEmpty() )
    {
60 61
        wxString      msg;
        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
}


75
EDA_GRAPHIC_TEXT_CTRL::~EDA_GRAPHIC_TEXT_CTRL()
76
{
77 78 79 80 81 82 83
    /* no, these are deleted by the BoxSizer
    delete m_FrameText;
    delete m_Title;
    */
}


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 88 89 90 91 92
    if( textSize < 10 )
        textSize = 10;

    if( textSize > 3000 )
        textSize = 3000;

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

109
void EDA_GRAPHIC_TEXT_CTRL::SetValue( int textSize )
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 119
    wxString text = m_FrameText->GetValue();
    return text;
120 121
}

122

123
int EDA_GRAPHIC_TEXT_CTRL::ParseSize( const wxString& sizeText, EDA_UNITS_T aUnit )
124
{
125 126
    int    textsize;

127
    textsize = ValueFromString( aUnit, sizeText );
128 129 130 131 132 133 134 135 136

    // Limit to reasonable size
    if( textsize < 10 )
        textsize = 10;

    if( textsize > 3000 )
        textsize = 3000;

    return textsize;
137 138
}

139

140
int EDA_GRAPHIC_TEXT_CTRL::GetTextSize()
141
{
142
    return ParseSize( m_FrameSize->GetValue(), m_UserUnit );
143 144 145
}


146
void EDA_GRAPHIC_TEXT_CTRL::Enable( bool state )
147 148 149 150
{
    m_FrameText->Enable( state );
}

151

152 153 154
/********************************************************/
/* Class to display and edit a coordinated INCHES or MM */
/********************************************************/
155 156 157 158
EDA_POSITION_CTRL::EDA_POSITION_CTRL( wxWindow*       parent,
                                      const wxString& title,
                                      const wxPoint&  pos_to_edit,
                                      EDA_UNITS_T     user_unit,
159
                                      wxBoxSizer*     BoxSizer )
160
{
161 162
    wxString text;

163
    m_UserUnit = user_unit;
164

165 166 167 168
    if( title.IsEmpty() )
        text = _( "Pos " );
    else
        text = title;
169

170
    text   += _( "X" ) + ReturnUnitSymbol( m_UserUnit );
171
    m_TextX = new wxStaticText( parent, -1, text );
172

173 174
    BoxSizer->Add( m_TextX, 0, wxGROW | wxLEFT | wxRIGHT | wxTOP, 5 );
    m_FramePosX = new wxTextCtrl( parent, -1, wxEmptyString, wxDefaultPosition );
175 176 177

    BoxSizer->Add( m_FramePosX, 0, wxGROW | wxLEFT | wxRIGHT | wxBOTTOM, 5 );

178

179 180 181 182
    if( title.IsEmpty() )
        text = _( "Pos " );
    else
        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 192 193
    BoxSizer->Add( m_FramePosY, 0, wxGROW | wxLEFT | wxRIGHT | wxBOTTOM, 5 );

    SetValue( pos_to_edit.x, pos_to_edit.y );
194 195 196
}


197
EDA_POSITION_CTRL::~EDA_POSITION_CTRL()
198
{
199 200 201 202
    delete m_TextX;
    delete m_TextY;
    delete m_FramePosX;
    delete m_FramePosY;
203 204
}

205

206
/* Returns (in internal units) to coordinate between (in user units)
207
 */
208
wxPoint EDA_POSITION_CTRL::GetValue()
209
{
210
    wxPoint coord;
211

212 213
    coord.x = ValueFromString( m_UserUnit, m_FramePosX->GetValue() );
    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 222
    m_FramePosX->Enable( x_win_on );
    m_FramePosY->Enable( y_win_on );
223 224
}

225

226
void EDA_POSITION_CTRL::SetValue( int x_value, int y_value )
227
{
228 229 230 231 232
    wxString msg;

    m_Pos_To_Edit.x = x_value;
    m_Pos_To_Edit.y = y_value;

233
    msg = StringFromValue( m_UserUnit, m_Pos_To_Edit.x );
234 235 236
    m_FramePosX->Clear();
    m_FramePosX->SetValue( msg );

237
    msg = StringFromValue( m_UserUnit, m_Pos_To_Edit.y );
238 239 240 241 242 243
    m_FramePosY->Clear();
    m_FramePosY->SetValue( msg );
}


/*******************/
244
/* EDA_SIZE_CTRL */
245
/*******************/
246
EDA_SIZE_CTRL::EDA_SIZE_CTRL( wxWindow* parent, const wxString& title,
247 248 249 250
                              const wxSize& size_to_edit, EDA_UNITS_T aUnit,
                              wxBoxSizer* aBoxSizer ) :
    EDA_POSITION_CTRL( parent, title, wxPoint( size_to_edit.x, size_to_edit.y ),
                       aUnit, aBoxSizer )
251 252 253
{
}

254

255
wxSize EDA_SIZE_CTRL::GetValue()
256
{
257
    wxPoint pos = EDA_POSITION_CTRL::GetValue();
258 259 260 261 262
    wxSize  size;

    size.x = pos.x;
    size.y = pos.y;
    return size;
263 264 265
}


266 267 268
/**************************************************************/
/* Class to display and edit a dimension INCHES, MM, or other */
/**************************************************************/
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 287 288
                   0,
                   wxGROW | wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT | wxBOTTOM,
                   5 );
289 290
}

291

292
EDA_VALUE_CTRL::~EDA_VALUE_CTRL()
293
{
294 295
    delete m_ValueCtrl;
    delete m_Text;
296 297
}

298

299
int EDA_VALUE_CTRL::GetValue()
300
{
301 302
    int      coord;
    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 312 313
    wxString buffer;

    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 323
    m_ValueCtrl->Enable( enbl );
    m_Text->Enable( enbl );
324
}