dialog_pcb_text_properties.cpp 7.71 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-2010 Jean-Pierre Charras <jean-pierre.charras@gpisa-lab.inpg.fr>
 * Copyright (C) 2010 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
 */

charras's avatar
charras committed
25 26 27
/***************************************************************************/
/* Dialog editor for text on copper and technical layers (TEXTE_PCB class) */
/***************************************************************************/
plyatov's avatar
plyatov committed
28

29
#include "dialog_pcb_text_properties.h"
plyatov's avatar
plyatov committed
30 31 32
#include "fctsys.h"
#include "gr_basic.h"
#include "common.h"
33
#include "class_drawpanel.h"
plyatov's avatar
plyatov committed
34
#include "pcbnew.h"
charras's avatar
charras committed
35
#include "wxPcbStruct.h"
36 37
#include "drawtxt.h"
#include "confirm.h"
jean-pierre charras's avatar
jean-pierre charras committed
38
#include "dialog_helpers.h"
plyatov's avatar
plyatov committed
39

40 41 42 43 44 45
/**
 *  DIALOG_PCB_TEXT_PROPERTIES, derived from DIALOG_PCB_TEXT_PROPERTIES_BASE
 *  @see dialog_dialog_pcb_text_properties_base.h and
 *  dialog_dialog_pcb_text_properties_base.cpp, automatically created by
 *  wxFormBuilder.
 */
plyatov's avatar
plyatov committed
46

47 48
DIALOG_PCB_TEXT_PROPERTIES::DIALOG_PCB_TEXT_PROPERTIES( WinEDA_PcbFrame* parent, TEXTE_PCB* passedTextPCB, wxDC* DC )
                            : DIALOG_PCB_TEXT_PROPERTIES_BASE( parent )
plyatov's avatar
plyatov committed
49
{
50 51 52
    m_Parent = parent;
    m_DC = DC;
    m_SelectedPCBText = passedTextPCB;
plyatov's avatar
plyatov committed
53

54 55 56 57
    MyInit();
    GetSizer()->SetSizeHints( this );
    Centre();
}
plyatov's avatar
plyatov committed
58

59 60 61
/**
 * Routine for main window class to launch text properties dialog.
 */
charras's avatar
charras committed
62
void WinEDA_PcbFrame::InstallTextPCBOptionsFrame( TEXTE_PCB* TextPCB, wxDC* DC )
plyatov's avatar
plyatov committed
63
{
64
    DrawPanel->m_IgnoreMouseEvents = TRUE;
65 66
    DIALOG_PCB_TEXT_PROPERTIES dlg( this, TextPCB, DC );
    dlg.ShowModal();
67 68
    DrawPanel->MouseToCursorSchema();
    DrawPanel->m_IgnoreMouseEvents = FALSE;
plyatov's avatar
plyatov committed
69 70
}

71
void DIALOG_PCB_TEXT_PROPERTIES::MyInit()
plyatov's avatar
plyatov committed
72
{
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
    SetFocus();

    // Put units symbols to text labels where appropriate
    AddUnitSymbol( *m_SizeXLabel );
    AddUnitSymbol( *m_SizeYLabel );
    AddUnitSymbol( *m_ThicknessLabel );
    AddUnitSymbol( *m_PositionXLabel );
    AddUnitSymbol( *m_PositionYLabel );

    // Fill fields with current values
    *m_TextContentCtrl << m_SelectedPCBText->m_Text;

    PutValueInLocalUnits( *m_SizeXCtrl, m_SelectedPCBText->m_Size.x,
        m_Parent->m_InternalUnits );
    PutValueInLocalUnits( *m_SizeYCtrl, m_SelectedPCBText->m_Size.y,
        m_Parent->m_InternalUnits );
    PutValueInLocalUnits( *m_ThicknessCtrl, m_SelectedPCBText->m_Thickness,
        m_Parent->m_InternalUnits );
    PutValueInLocalUnits( *m_PositionXCtrl, m_SelectedPCBText->m_Pos.x,
        m_Parent->m_InternalUnits );
    PutValueInLocalUnits( *m_PositionYCtrl, m_SelectedPCBText->m_Pos.y,
        m_Parent->m_InternalUnits );

    for( int layer = 0; layer < NB_LAYERS;  ++layer )
97
    {
98
        m_LayerSelectionCtrl->Append( m_Parent->GetBoard()->GetLayerName( layer ) );
99
    }
100
     m_LayerSelectionCtrl->SetSelection( m_SelectedPCBText->GetLayer() );
101

102
    switch( m_SelectedPCBText->m_Orient )
103
    {
104 105 106 107 108 109 110 111 112 113 114 115
        default:
            m_OrientationCtrl->SetSelection( 0 );
            break;
        case 900:
            m_OrientationCtrl->SetSelection( 1 );
            break;
        case 1800:
            m_OrientationCtrl->SetSelection( 2 );
            break;
        case 2700:
            m_OrientationCtrl->SetSelection( 3 );
            break;
116 117
    }

118 119 120 121
    if( m_SelectedPCBText->m_Mirror )
        m_DisplayCtrl->SetSelection( 1 );
    else
        m_DisplayCtrl->SetSelection( 0 );
122

123 124 125 126
    if( m_SelectedPCBText->m_Italic )
        m_StyleCtrl->SetSelection( 1 );
    else
        m_StyleCtrl->SetSelection( 0 );
charras's avatar
charras committed
127

128 129 130
    // Set focus on most important control
    m_TextContentCtrl->SetFocus();
    m_TextContentCtrl->SetSelection( -1, -1 );
plyatov's avatar
plyatov committed
131 132
}

133
void DIALOG_PCB_TEXT_PROPERTIES::OnCancelClick( wxCommandEvent& event )
plyatov's avatar
plyatov committed
134
{
135
    EndModal( wxID_CANCEL );
plyatov's avatar
plyatov committed
136 137
}

138
void DIALOG_PCB_TEXT_PROPERTIES::OnOkClick( wxCommandEvent& event )
plyatov's avatar
plyatov committed
139
{
140 141 142
    wxPoint newPosition;
    wxSize  newSize;

143 144
    // If no other command in progress, prepare undo command
    // (for a command in progress, will be made later, at the completion of command)
145 146
    if( m_SelectedPCBText->m_Flags == 0 )
        m_Parent->SaveCopyInUndoList( m_SelectedPCBText, UR_CHANGED );
147 148 149 150 151

    /* set flag in edit to force undo/redo/abort proper operation,
     * and avoid new calls to SaveCopyInUndoList for the same text
     * this can occurs when a text is moved, and then rotated, edited ..
    */
152 153
    if( m_SelectedPCBText->m_Flags != 0 )
        m_SelectedPCBText->m_Flags |= IN_EDIT;
154

155 156
    // Erase old text on screen if context is available
    if( m_DC )
157
    {
158
        m_SelectedPCBText->Draw( m_Parent->DrawPanel, m_DC, GR_XOR );
159 160
    }

161 162
    // Set the new text content
    if( !m_TextContentCtrl->GetValue().IsEmpty() )
163
    {
164
        m_SelectedPCBText->m_Text = m_TextContentCtrl->GetValue();
165
    }
166

167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
    // Set PCB Text position
    newPosition.x = ReturnValueFromString( g_UserUnit, m_PositionXCtrl->GetValue(), m_Parent->m_InternalUnits );
    newPosition.y = ReturnValueFromString( g_UserUnit, m_PositionYCtrl->GetValue(), m_Parent->m_InternalUnits );
    m_SelectedPCBText->m_Pos  = newPosition;

    // Check constraints and set PCB Text size
    newSize.x = ReturnValueFromString( g_UserUnit, m_SizeXCtrl->GetValue(), m_Parent->m_InternalUnits );
    newSize.y = ReturnValueFromString( g_UserUnit, m_SizeYCtrl->GetValue(), m_Parent->m_InternalUnits );
    if( newSize.x < TEXTS_MIN_SIZE )
        newSize.x = TEXTS_MIN_SIZE;
    if( newSize.y < TEXTS_MIN_SIZE )
        newSize.y = TEXTS_MIN_SIZE;
    if( newSize.x > TEXTS_MAX_WIDTH )
        newSize.x = TEXTS_MAX_WIDTH;
    if( newSize.y > TEXTS_MAX_WIDTH )
        newSize.y = TEXTS_MAX_WIDTH;
    m_SelectedPCBText->m_Size = newSize;

    // Set the new thickness
    m_SelectedPCBText->m_Thickness = ReturnValueFromString( g_UserUnit, m_ThicknessCtrl->GetValue(), m_Parent->m_InternalUnits );

    // Test for acceptable values for thickness and size and clamp if fails
    int maxthickness = Clamp_Text_PenSize( m_SelectedPCBText->m_Thickness, m_SelectedPCBText->m_Size  );
    if( m_SelectedPCBText->m_Thickness > maxthickness )
191
    {
192
        DisplayError(NULL, _("The text thickness is too large for the text size. It will be clamped"));
193
        m_SelectedPCBText->m_Thickness = maxthickness;
194
    }
195

196 197 198 199 200 201 202 203 204 205 206
    // Set the layer on which the PCB text is laying
    m_SelectedPCBText->SetLayer(  m_LayerSelectionCtrl->GetSelection() );

    // Set whether the PCB text is mirrored (faced down from layer face perspective)
    m_SelectedPCBText->m_Mirror = (m_DisplayCtrl->GetSelection() == 1) ? true : false;

    // Set the text orientation
    m_SelectedPCBText->m_Orient = m_OrientationCtrl->GetSelection() * 900;

    // Set whether the PCB text is slanted (it is not italics, as italics has additional curves in style)
    m_SelectedPCBText->m_Italic = m_StyleCtrl->GetSelection() ? 1 : 0;
207

208 209
    // Finally, display new text if there is a context to do so
    if( m_DC )
210
    {
211
        m_SelectedPCBText->Draw( m_Parent->DrawPanel, m_DC, GR_OR );
212
    }
213
    m_Parent->OnModify();
214
    EndModal( 1 );
plyatov's avatar
plyatov committed
215
}