dialog_graphic_item_properties.cpp 7.64 KB
Newer Older
1 2 3
/*
 * This program source code file is part of KiCad, a free EDA CAD application.
 *
4 5
 * Copyright (C) 2010 Jean-Pierre Charras <jp.charras@wanadoo.fr>
 * Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
 *
 * 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
 */
24

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

29 30 31 32 33 34 35 36
/* Edit parameters values of graphic items type DRAWSEGMENTS:
 * Lines
 * Circles
 * Arcs
 * used as graphic elements found on non copper layers in boards
 * items on edge layers are considered as graphic items
 * Pcb texts are not always graphic items and are not handled here
 */
37 38 39 40 41 42 43 44
#include <fctsys.h>
#include <macros.h>
#include <gr_basic.h>
#include <confirm.h>
#include <class_drawpanel.h>
#include <pcbnew.h>
#include <wxPcbStruct.h>
#include <class_board_design_settings.h>
45
#include <base_units.h>
46 47 48 49 50

#include <class_board.h>
#include <class_drawsegment.h>

#include <dialog_graphic_item_properties_base.h>
51
#include <class_pcb_layer_box_selector.h>
52

53

54
class DIALOG_GRAPHIC_ITEM_PROPERTIES: public DIALOG_GRAPHIC_ITEM_PROPERTIES_BASE
55 56
{
private:
57
    PCB_EDIT_FRAME* m_parent;
58 59
    wxDC* m_DC;
    DRAWSEGMENT* m_Item;
60
    BOARD_DESIGN_SETTINGS  m_brdSettings;
61 62

public:
63 64
    DIALOG_GRAPHIC_ITEM_PROPERTIES( PCB_EDIT_FRAME* aParent, DRAWSEGMENT * aItem, wxDC * aDC);
    ~DIALOG_GRAPHIC_ITEM_PROPERTIES() {};
65 66

private:
67
    void initDlg( );
68
    void OnOkClick( wxCommandEvent& event );
69
    void OnCancelClick( wxCommandEvent& event ) { event.Skip(); }
70
    void OnLayerChoice( wxCommandEvent& event );
71 72
};

73
DIALOG_GRAPHIC_ITEM_PROPERTIES::DIALOG_GRAPHIC_ITEM_PROPERTIES( PCB_EDIT_FRAME* aParent,
74
                                                                DRAWSEGMENT * aItem, wxDC * aDC ):
75
    DIALOG_GRAPHIC_ITEM_PROPERTIES_BASE( aParent )
76
{
77
    m_parent = aParent;
78 79
    m_DC = aDC;
    m_Item = aItem;
80
    m_brdSettings = m_parent->GetDesignSettings();
81
    initDlg();
charras's avatar
charras committed
82 83
    Layout();
    GetSizer()->SetSizeHints( this );
84
    Centre();
85 86 87
}


88
void PCB_EDIT_FRAME::InstallGraphicItemPropertiesDialog( DRAWSEGMENT* aItem, wxDC* aDC )
89
{
90 91
    if ( aItem == NULL )
    {
92
        DisplayError( this, wxT( "InstallGraphicItemPropertiesDialog() error: NULL item" ) );
93 94
        return;
    }
95

96
    m_canvas->SetIgnoreMouseEvents( true );
97 98
    DIALOG_GRAPHIC_ITEM_PROPERTIES dlg( this, aItem, aDC );
    dlg.ShowModal();
99
    m_canvas->MoveCursorToCrossHair();
100
    m_canvas->SetIgnoreMouseEvents( false );
101 102
}

103

104
void DIALOG_GRAPHIC_ITEM_PROPERTIES::initDlg( )
105
{
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
    m_StandardButtonsSizerOK->SetDefault();

    // Set unit symbol
    wxStaticText * texts_unit[] =
    {
        m_StartPointXUnit,
        m_StartPointYUnit,
        m_EndPointXUnit,
        m_EndPointYUnit,
        m_ThicknessTextUnit,
        m_DefaulThicknessTextUnit,
        NULL
    };

    for( int ii = 0; ; ii++ )
    {
        if( texts_unit[ii] == NULL )
            break;
124

125 126
        texts_unit[ii]->SetLabel( GetAbbreviatedUnitsLabel() );
    }
127 128

    wxString msg;
Dick Hollenbeck's avatar
Dick Hollenbeck committed
129

130
    // Change texts according to the segment shape:
Dick Hollenbeck's avatar
Dick Hollenbeck committed
131
    switch ( m_Item->GetShape() )
132
    {
Dick Hollenbeck's avatar
Dick Hollenbeck committed
133
    case S_CIRCLE:
134 135 136 137 138 139 140
        m_StartPointXLabel->SetLabel( _( "Center X" ) );
        m_StartPointYLabel->SetLabel( _( "Center Y" ) );
        m_EndPointXLabel->SetLabel( _( "Point X" ) );
        m_EndPointYLabel->SetLabel( _( "Point Y" ) );
        m_Angle_Text->Show( false );
        m_Angle_Ctrl->Show( false );
        m_AngleUnit->Show( false );
Dick Hollenbeck's avatar
Dick Hollenbeck committed
141 142 143
        break;

    case S_ARC:
144 145 146 147
        m_StartPointXLabel->SetLabel( _( "Center X" ) );
        m_StartPointYLabel->SetLabel( _( "Center Y" ) );
        m_EndPointXLabel->SetLabel( _( "Start Point X" ) );
        m_EndPointYLabel->SetLabel( _( "Start Point Y" ) );
148

149
        // Here the angle is a double, but the UI is still working with integers.
150
        msg << int( m_Item->GetAngle() );
151
        m_Angle_Ctrl->SetValue( msg );
Dick Hollenbeck's avatar
Dick Hollenbeck committed
152 153 154
        break;

    default:
155 156 157
        m_Angle_Text->Show( false );
        m_Angle_Ctrl->Show( false );
        m_AngleUnit->Show( false );
Dick Hollenbeck's avatar
Dick Hollenbeck committed
158
        break;
159
    }
Dick Hollenbeck's avatar
Dick Hollenbeck committed
160

161
    PutValueInLocalUnits( *m_Center_StartXCtrl, m_Item->GetStart().x );
162

163
    PutValueInLocalUnits( *m_Center_StartYCtrl, m_Item->GetStart().y );
164

165
    PutValueInLocalUnits( *m_EndX_Radius_Ctrl, m_Item->GetEnd().x );
166

167
    PutValueInLocalUnits( *m_EndY_Ctrl, m_Item->GetEnd().y );
168

169
    PutValueInLocalUnits( *m_ThicknessCtrl, m_Item->GetWidth() );
Dick Hollenbeck's avatar
Dick Hollenbeck committed
170

171
    int thickness;
Dick Hollenbeck's avatar
Dick Hollenbeck committed
172

173
    if( m_Item->GetLayer() == EDGE_N )
174
        thickness =  m_brdSettings.m_EdgeSegmentWidth;
175
    else
176
        thickness =  m_brdSettings.m_DrawSegmentWidth;
Dick Hollenbeck's avatar
Dick Hollenbeck committed
177

178
    PutValueInLocalUnits( *m_DefaultThicknessCtrl, thickness );
179

180 181 182 183 184
    // Configure the layers list selector
    m_LayerSelectionCtrl->SetLayersHotkeys( false );
    m_LayerSelectionCtrl->SetLayerMask( ALL_CU_LAYERS );
    m_LayerSelectionCtrl->SetBoardFrame( m_parent );
    m_LayerSelectionCtrl->Resync();
185

186
    if( m_LayerSelectionCtrl->SetLayerSelection( m_Item->GetLayer() ) < 0 )
187
    {
188 189
        wxMessageBox( _( "This item has an illegal layer id.\n"
                         "Now, forced on the drawings layer. Please, fix it" ) );
190
        m_LayerSelectionCtrl->SetLayerSelection( DRAW_N );
191 192 193 194
    }
}


195
void DIALOG_GRAPHIC_ITEM_PROPERTIES::OnLayerChoice( wxCommandEvent& event )
196
{
197
    int thickness;
Dick Hollenbeck's avatar
Dick Hollenbeck committed
198

199
    if( m_LayerSelectionCtrl->GetLayerSelection() == EDGE_N )
200
        thickness =  m_brdSettings.m_EdgeSegmentWidth;
201
    else
202
        thickness =  m_brdSettings.m_DrawSegmentWidth;
Dick Hollenbeck's avatar
Dick Hollenbeck committed
203

204
    PutValueInLocalUnits( *m_DefaultThicknessCtrl, thickness );
205 206
}

207

208
void DIALOG_GRAPHIC_ITEM_PROPERTIES::OnOkClick( wxCommandEvent& event )
209
{
210
    m_parent->SaveCopyInUndoList( m_Item, UR_CHANGED );
charras's avatar
charras committed
211

212
    wxString msg;
213

Dick Hollenbeck's avatar
Dick Hollenbeck committed
214
    if( m_DC )
215
        m_Item->Draw( m_parent->GetCanvas(), m_DC, GR_XOR );
216 217

    msg = m_Center_StartXCtrl->GetValue();
218
    m_Item->SetStartX( ReturnValueFromString( g_UserUnit, msg ) );
219 220

    msg = m_Center_StartYCtrl->GetValue();
221
    m_Item->SetStartY( ReturnValueFromString( g_UserUnit, msg ) );
222 223

    msg = m_EndX_Radius_Ctrl->GetValue();
224
    m_Item->SetEndX( ReturnValueFromString( g_UserUnit, msg ) );
225 226

    msg = m_EndY_Ctrl->GetValue();
227
    m_Item->SetEndY( ReturnValueFromString( g_UserUnit, msg ) );
228 229

    msg = m_ThicknessCtrl->GetValue();
230
    m_Item->SetWidth( ReturnValueFromString( g_UserUnit, msg ) );
231 232

    msg = m_DefaultThicknessCtrl->GetValue();
233
    int thickness = ReturnValueFromString( g_UserUnit, msg );
234

235
    m_Item->SetLayer( m_LayerSelectionCtrl->GetLayerSelection() );
236

237
    if( m_Item->GetLayer() == EDGE_N )
238
         m_brdSettings.m_EdgeSegmentWidth = thickness;
239
    else
240
         m_brdSettings.m_DrawSegmentWidth = thickness;
241

Dick Hollenbeck's avatar
Dick Hollenbeck committed
242
    if( m_Item->GetShape() == S_ARC )
243
    {
Dick Hollenbeck's avatar
Dick Hollenbeck committed
244 245
        double angle;
        m_Angle_Ctrl->GetValue().ToDouble( &angle );
246
        NORMALIZE_ANGLE_360(angle);
Dick Hollenbeck's avatar
Dick Hollenbeck committed
247
        m_Item->SetAngle( angle );
248
    }
249

250
    m_parent->OnModify();
251

Dick Hollenbeck's avatar
Dick Hollenbeck committed
252
    if( m_DC )
253
        m_Item->Draw( m_parent->GetCanvas(), m_DC, GR_OR );
254

255
    m_parent->SetMsgPanel( m_Item );
256

257
    m_parent->SetDesignSettings( m_brdSettings );
Dick Hollenbeck's avatar
Dick Hollenbeck committed
258

259
    Close( true );
260
}