dialog_lib_edit_text.cpp 6.32 KB
Newer Older
jean-pierre charras's avatar
jean-pierre charras committed
1 2
/**
 * @file dialog_lib_edit_text.cpp
3
 * @brief dialog to editing graphic texts (not fields) in body components.
jean-pierre charras's avatar
jean-pierre charras committed
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
 */

/*
 * This program source code file is part of KiCad, a free EDA CAD application.
 *
 * Copyright (C) 20011 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
 * Copyright (C) 2004-2011 KiCad Developers, see change_log.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
 */
29

30 31 32 33
#include <fctsys.h>
#include <gr_basic.h>
#include <common.h>
#include <class_drawpanel.h>
34
#include <base_units.h>
35

36 37 38 39
#include <general.h>
#include <libeditframe.h>
#include <class_libentry.h>
#include <lib_text.h>
40

41
#include <dialog_lib_edit_text.h>
42 43


44
DIALOG_LIB_EDIT_TEXT::DIALOG_LIB_EDIT_TEXT( LIB_EDIT_FRAME* aParent, LIB_TEXT* aText ) :
45
    DIALOG_LIB_EDIT_TEXT_BASE( aParent )
46
{
47 48
    m_parent = aParent;
    m_graphicText = aText;
jean-pierre charras's avatar
jean-pierre charras committed
49 50 51 52
    initDlg();

    GetSizer()->SetSizeHints(this);
    Centre();
53 54 55
}


jean-pierre charras's avatar
jean-pierre charras committed
56
void DIALOG_LIB_EDIT_TEXT::initDlg( )
57
{
58 59
    wxString msg;

jean-pierre charras's avatar
jean-pierre charras committed
60
    m_TextValue->SetFocus();
61

62 63 64 65
    // Disable options for fieldedition, not existing in  graphic text
    m_Invisible->Show(false);

    if ( m_graphicText )
66
    {
67
        msg = ReturnStringFromValue( g_UserUnit, m_graphicText->GetSize().x );
68
        m_TextSize->SetValue( msg );
69
        m_TextValue->SetValue( m_graphicText->GetText() );
70

71
        if ( m_graphicText->GetUnit() == 0 )
72
            m_CommonUnit->SetValue( true );
73
        if ( m_graphicText->GetConvert() == 0 )
74
            m_CommonConvert->SetValue( true );
75
        if ( m_graphicText->GetOrientation() == TEXT_ORIENT_VERT )
76
            m_Orient->SetValue( true );
77 78

        int shape = 0;
79
        if ( m_graphicText->IsItalic() )
80
            shape = 1;
81
        if ( m_graphicText->IsBold() )
82 83 84 85
            shape |= 2;

        m_TextShapeOpt->SetSelection( shape );

86
        switch ( m_graphicText->GetHorizJustify() )
87 88
        {
            case GR_TEXT_HJUSTIFY_LEFT:
89
                m_TextHJustificationOpt->SetSelection( 0 );
90 91 92
                break;

            case GR_TEXT_HJUSTIFY_CENTER:
93
                m_TextHJustificationOpt->SetSelection( 1 );
94 95 96
                break;

            case GR_TEXT_HJUSTIFY_RIGHT:
97
                m_TextHJustificationOpt->SetSelection( 2 );
98 99 100 101
                break;

        }

102
        switch ( m_graphicText->GetVertJustify() )
103
        {
104
        case GR_TEXT_VJUSTIFY_BOTTOM:
105
            m_TextVJustificationOpt->SetSelection( 0 );
106
            break;
107

108
        case GR_TEXT_VJUSTIFY_CENTER:
109
            m_TextVJustificationOpt->SetSelection( 1 );
110
            break;
111

112
        case GR_TEXT_VJUSTIFY_TOP:
113
            m_TextVJustificationOpt->SetSelection( 2 );
114
            break;
115
        }
116 117 118
    }
    else
    {
119
        msg = ReturnStringFromValue( g_UserUnit, m_parent->m_textSize );
120 121
        m_TextSize->SetValue( msg );

122
        if ( ! m_parent->m_drawSpecificUnit )
123
            m_CommonUnit->SetValue( true );
124
        if ( ! m_parent->m_drawSpecificConvert )
125
            m_CommonConvert->SetValue( true );
126
        if ( m_parent->m_textOrientation == TEXT_ORIENT_VERT )
127
            m_Orient->SetValue( true );
128 129 130 131 132
    }

    msg = m_TextSizeText->GetLabel() + ReturnUnitSymbol();
    m_TextSizeText->SetLabel( msg );

jean-pierre charras's avatar
jean-pierre charras committed
133
    m_sdbSizerButtonsOK->SetDefault();
134 135 136
}


137
void DIALOG_LIB_EDIT_TEXT::OnCancelClick( wxCommandEvent& event )
138
{
139
    EndModal(wxID_CANCEL);
140 141 142
}


143
/* Updates the different parameters for the component being edited */
144
void DIALOG_LIB_EDIT_TEXT::OnOkClick( wxCommandEvent& event )
145
{
146
    wxString Line;
147

148
    Line = m_TextValue->GetValue();
149
    m_parent->m_textOrientation = m_Orient->GetValue() ? TEXT_ORIENT_VERT : TEXT_ORIENT_HORIZ;
150
    wxString msg = m_TextSize->GetValue();
151
    m_parent->m_textSize = ReturnValueFromString( g_UserUnit, msg );
152 153
    m_parent->m_drawSpecificConvert = m_CommonConvert->GetValue() ? false : true;
    m_parent->m_drawSpecificUnit = m_CommonUnit->GetValue() ? false : true;
154

155
    if( m_graphicText )
156
    {
157
        if( ! Line.IsEmpty() )
158
            m_graphicText->SetText( Line );
159
        else
160
            m_graphicText->SetText( wxT( "[null]" ) );
161

162 163
        m_graphicText->SetSize( wxSize( m_parent->m_textSize, m_parent->m_textSize ) );
        m_graphicText->SetOrientation( m_parent->m_textOrientation );
164

165 166
        if( m_parent->m_drawSpecificUnit )
            m_graphicText->SetUnit( m_parent->GetUnit() );
167
        else
168
            m_graphicText->SetUnit( 0 );
169

170 171
        if( m_parent->m_drawSpecificConvert )
            m_graphicText->SetConvert( m_parent->GetConvert() );
172
        else
173
            m_graphicText->SetConvert( 0 );
174

175 176
        m_graphicText->SetItalic( ( m_TextShapeOpt->GetSelection() & 1 ) != 0 );
        m_graphicText->SetBold( ( m_TextShapeOpt->GetSelection() & 2 ) != 0 );
177

178
        switch( m_TextHJustificationOpt->GetSelection() )
179
        {
180
        case 0:
181
            m_graphicText->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
182
            break;
183

184
        case 1:
185
            m_graphicText->SetHorizJustify( GR_TEXT_HJUSTIFY_CENTER );
186
            break;
187

188
        case 2:
189
            m_graphicText->SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
190
            break;
191 192
        }

193
        switch( m_TextVJustificationOpt->GetSelection() )
194
        {
195
        case 0:
196
            m_graphicText->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
197
            break;
198

199
        case 1:
200
            m_graphicText->SetVertJustify( GR_TEXT_VJUSTIFY_CENTER );
201
            break;
202

203
        case 2:
204
            m_graphicText->SetVertJustify( GR_TEXT_VJUSTIFY_TOP );
205
            break;
206
        }
207
    }
208

209
    if( m_parent->GetDrawItem() )
210
        m_parent->SetMsgPanel( m_parent->GetDrawItem() );
211

212
    EndModal(wxID_OK);
213
}