dialog_edit_module_text.cpp 6.84 KB
Newer Older
1
/**
2 3
 * @file dialog_edit_module_text.cpp
 * @brief dialog editor for texts (fields) in footprints.
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 29 30
 */

/*
 * This program source code file is part of KiCad, a free EDA CAD application.
 *
 * Copyright (C) 2013 Jean-Pierre Charras
 * Copyright (C) 2013 Dick Hollenbeck, dick@softplc.com
 * Copyright (C) 2008-2013 Wayne Stambaugh <stambaughw@verizon.net>
 * Copyright (C) 1992-2013 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
 */
31 32


33 34 35 36 37 38 39 40 41
#include <fctsys.h>
#include <macros.h>
#include <gr_basic.h>
#include <common.h>
#include <class_drawpanel.h>
#include <pcbnew.h>
#include <drawtxt.h>
#include <confirm.h>
#include <wxBasePcbFrame.h>
42
#include <base_units.h>
43 44 45 46 47

#include <class_module.h>
#include <class_text_mod.h>

#include <dialog_edit_module_text_base.h>
48

49

50 51
extern wxPoint MoveVector;  // Move vector for move edge, imported from edtxtmod.cpp

52

53 54 55 56 57 58
/*************** **************/
/* class DialogEditModuleText */
/*************** **************/
class DialogEditModuleText : public DialogEditModuleText_base
{
private:
59 60 61 62
    PCB_BASE_FRAME* m_parent;
    wxDC* m_dc;
    MODULE* m_module;
    TEXTE_MODULE* m_currentText;
63 64

public:
65
    DialogEditModuleText( PCB_BASE_FRAME* aParent, TEXTE_MODULE* aTextMod, wxDC* aDC );
66
    ~DialogEditModuleText() {};
67 68

private:
69
    void initDlg( );
70 71
    void OnOkClick( wxCommandEvent& event );
    void OnCancelClick( wxCommandEvent& event );
72 73
};

74

75
void PCB_BASE_FRAME::InstallTextModOptionsFrame( TEXTE_MODULE* TextMod, wxDC* DC )
76
{
77
    m_canvas->SetIgnoreMouseEvents( true );
charras's avatar
charras committed
78 79
    DialogEditModuleText dialog( this, TextMod, DC );
    dialog.ShowModal();
80
    m_canvas->SetIgnoreMouseEvents( false );
81 82 83
}


84 85 86
DialogEditModuleText::DialogEditModuleText( PCB_BASE_FRAME* aParent,
                                            TEXTE_MODULE* aTextMod, wxDC* aDC ) :
    DialogEditModuleText_base( aParent )
87 88

{
89 90 91 92
    m_parent = aParent;
    m_dc     = aDC;
    m_module = NULL;
    m_currentText = aTextMod;
93

94 95
    if( m_currentText )
        m_module = (MODULE*) m_currentText->GetParent();
96

97
    initDlg( );
98

99
    m_buttonOK->SetDefault();
100 101
    GetSizer()->Fit( this );
    GetSizer()->SetSizeHints( this );
102 103

    Centre();
104 105 106 107 108
}


void DialogEditModuleText::OnCancelClick( wxCommandEvent& event )
{
109
   EndModal(0);
110 111 112
}


113
void DialogEditModuleText::initDlg( )
114
{
115
    SetFocus();
116 117 118

    wxString msg;

119
    if( m_module )
120 121 122
    {
        wxString format = m_ModuleInfoText->GetLabel();
        msg.Printf( format,
123 124
                    GetChars( m_module->GetReference() ),
                    GetChars( m_module->GetValue() ),
125
                    m_module->GetOrientation() / 10.0 );
126
    }
charras's avatar
charras committed
127
    else
128
    {
charras's avatar
charras committed
129
        msg.Empty();
130
    }
charras's avatar
charras committed
131 132 133

    m_ModuleInfoText->SetLabel( msg );

134 135 136
    switch( m_currentText->GetType() )
    {
    case TEXTE_MODULE::TEXT_is_VALUE:
137
        m_TextDataTitle->SetLabel( _( "Value:" ) );
138 139 140
        break;

    case TEXTE_MODULE::TEXT_is_DIVERS:
141
        m_TextDataTitle->SetLabel( _( "Text:" ) );
142 143 144 145 146 147
        break;

    default:
        m_TextDataTitle->SetLabel( _( "Reference:" ) );
        break;
    }
148

149
    m_Name->SetValue( m_currentText->GetText() );
150

151
    m_Style->SetSelection( m_currentText->IsItalic() ? 1 : 0 );
152 153

    AddUnitSymbol( *m_SizeXTitle );
154
    PutValueInLocalUnits( *m_TxtSizeCtrlX, m_currentText->GetSize().x );
155 156

    AddUnitSymbol( *m_SizeYTitle );
157
    PutValueInLocalUnits( *m_TxtSizeCtrlY, m_currentText->GetSize().y );
158 159

    AddUnitSymbol( *m_PosXTitle );
160
    PutValueInLocalUnits( *m_TxtPosCtrlX, m_currentText->GetPos0().x );
161 162

    AddUnitSymbol( *m_PosYTitle );
163
    PutValueInLocalUnits( *m_TxtPosCtrlY, m_currentText->GetPos0().y );
164 165

    AddUnitSymbol( *m_WidthTitle );
166
    PutValueInLocalUnits( *m_TxtWidthCtlr, m_currentText->GetThickness() );
167

168
    double text_orient = m_currentText->GetOrientation();
169
    NORMALIZE_ANGLE_90( text_orient );
170

171 172 173
    if( (text_orient != 0) )
        m_Orient->SetSelection( 1 );

Dick Hollenbeck's avatar
Dick Hollenbeck committed
174
    if( !m_currentText->IsVisible() )
175 176 177 178 179 180 181 182
        m_Show->SetSelection( 1 );;
}


void DialogEditModuleText::OnOkClick( wxCommandEvent& event )
{
    wxString msg;

183 184
    if ( m_module)
        m_parent->SaveCopyInUndoList( m_module, UR_CHANGED );
185

186
    if( m_dc )     //Erase old text on screen
187
    {
188
        m_currentText->Draw( m_parent->GetCanvas(), m_dc, GR_XOR,
189
                             (m_currentText->IsMoving()) ? MoveVector : wxPoint( 0, 0 ) );
190 191
    }

192 193
    m_currentText->SetText( m_Name->GetValue() );
    m_currentText->SetItalic( m_Style->GetSelection() == 1 );
194

Dick Hollenbeck's avatar
Dick Hollenbeck committed
195
    wxPoint tmp;
196 197

    msg = m_TxtPosCtrlX->GetValue();
198
    tmp.x = ReturnValueFromString( g_UserUnit, msg );
Dick Hollenbeck's avatar
Dick Hollenbeck committed
199

200
    msg = m_TxtPosCtrlY->GetValue();
201
    tmp.y = ReturnValueFromString( g_UserUnit, msg );
Dick Hollenbeck's avatar
Dick Hollenbeck committed
202 203

    m_currentText->SetPos0( tmp );
204

205 206
    wxSize textSize( wxSize( ReturnValueFromString( g_UserUnit, m_TxtSizeCtrlX->GetValue() ),
                             ReturnValueFromString( g_UserUnit, m_TxtSizeCtrlY->GetValue() ) ) );
207 208

    // Test for a reasonnable size:
209 210 211 212 213 214
    if( textSize.x < TEXTS_MIN_SIZE )
        textSize.x = TEXTS_MIN_SIZE;
    if( textSize.y < TEXTS_MIN_SIZE )
        textSize.y = TEXTS_MIN_SIZE;

    m_currentText->SetSize( textSize ),
215 216

    msg = m_TxtWidthCtlr->GetValue();
217
    int width = ReturnValueFromString( g_UserUnit, msg );
218 219 220 221

    // Test for a reasonnable width:
    if( width <= 1 )
        width = 1;
222

223
    int maxthickness = Clamp_Text_PenSize(width, m_currentText->GetSize() );
224

225 226
    if( width > maxthickness )
    {
227 228
        DisplayError( NULL,
                      _( "The text thickness is too large for the text size. It will be clamped" ) );
229 230
        width = maxthickness;
    }
231

232
    m_currentText->SetThickness( width );
233

Dick Hollenbeck's avatar
Dick Hollenbeck committed
234 235
    m_currentText->SetVisible( m_Show->GetSelection() == 0 );

236
    int text_orient = (m_Orient->GetSelection() == 0) ? 0 : 900;
237
    m_currentText->SetOrientation( text_orient );
238

239
    m_currentText->SetDrawCoord();
240

241
    if( m_dc )     // Display new text
242
    {
243
        m_currentText->Draw( m_parent->GetCanvas(), m_dc, GR_XOR,
244
                             (m_currentText->IsMoving()) ? MoveVector : wxPoint( 0, 0 ) );
245
    }
246

247
    m_parent->OnModify();
248

249
    if( m_module )
250
        m_module->SetLastEditTime();
251

252
    EndModal(1);
253
}