dialog_graphic_item_properties.cpp 7.47 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
/**************************************/
/* dialog_graphic_item_properties.cpp */
/**************************************/

/* 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
 */
13 14 15 16 17 18 19 20
#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>
21
#include <base_units.h>
22 23 24 25 26

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

#include <dialog_graphic_item_properties_base.h>
27
#include <class_pcb_layer_box_selector.h>
28

29
class DIALOG_GRAPHIC_ITEM_PROPERTIES: public DIALOG_GRAPHIC_ITEM_PROPERTIES_BASE
30 31
{
private:
32
    PCB_EDIT_FRAME* m_parent;
33 34
    wxDC* m_DC;
    DRAWSEGMENT* m_Item;
35
    BOARD_DESIGN_SETTINGS  m_brdSettings;
36 37

public:
38 39
    DIALOG_GRAPHIC_ITEM_PROPERTIES( PCB_EDIT_FRAME* aParent, DRAWSEGMENT * aItem, wxDC * aDC);
    ~DIALOG_GRAPHIC_ITEM_PROPERTIES() {};
40 41

private:
42
    void initDlg( );
43 44 45
    void OnOkClick( wxCommandEvent& event );
    void OnCancelClick( wxCommandEvent& event );
    void OnLayerChoice( wxCommandEvent& event );
46 47
};

48
DIALOG_GRAPHIC_ITEM_PROPERTIES::DIALOG_GRAPHIC_ITEM_PROPERTIES( PCB_EDIT_FRAME* aParent,
49
                                                          DRAWSEGMENT * aItem, wxDC * aDC):
50
    DIALOG_GRAPHIC_ITEM_PROPERTIES_BASE( aParent )
51
{
52
    m_parent = aParent;
53 54
    m_DC = aDC;
    m_Item = aItem;
55
    m_brdSettings = m_parent->GetDesignSettings();
56
    initDlg();
charras's avatar
charras committed
57 58
    Layout();
    GetSizer()->SetSizeHints( this );
59
    Centre();
60 61 62 63
}


/*******************************************************************************************/
64
void PCB_EDIT_FRAME::InstallGraphicItemPropertiesDialog(DRAWSEGMENT * aItem, wxDC* aDC)
65 66
/*******************************************************************************************/
{
67 68
    if ( aItem == NULL )
    {
charras's avatar
charras committed
69
        DisplayError(this, wxT("InstallGraphicItemPropertiesDialog() error: NULL item"));
70 71
        return;
    }
72

73
    m_canvas->SetIgnoreMouseEvents( true );
74 75 76
    DIALOG_GRAPHIC_ITEM_PROPERTIES* dialog = new DIALOG_GRAPHIC_ITEM_PROPERTIES( this, aItem, aDC );
    dialog->ShowModal();
    dialog->Destroy();
77
    m_canvas->MoveCursorToCrossHair();
78
    m_canvas->SetIgnoreMouseEvents( false );
79 80 81
}

/**************************************************************************/
82
void DIALOG_GRAPHIC_ITEM_PROPERTIES::initDlg( )
83 84 85 86 87
/**************************************************************************/
/* Initialize messages and values in text control,
 * according to the item parameters values
*/
{
88
    SetFocus();
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
    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;
        texts_unit[ii]->SetLabel( GetAbbreviatedUnitsLabel() );
    }
109 110

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

112
    // Change texts according to the segment shape:
Dick Hollenbeck's avatar
Dick Hollenbeck committed
113
    switch ( m_Item->GetShape() )
114
    {
Dick Hollenbeck's avatar
Dick Hollenbeck committed
115
    case S_CIRCLE:
116 117 118 119
        m_StartPointXLabel->SetLabel(_("Center X"));
        m_StartPointYLabel->SetLabel(_("Center Y"));
        m_EndPointXLabel->SetLabel(_("Point X"));
        m_EndPointYLabel->SetLabel(_("Point Y"));
Dick Hollenbeck's avatar
Dick Hollenbeck committed
120 121
        m_Angle_Text->Show(false);
        m_Angle_Ctrl->Show(false);
122
        m_AngleUnit->Show(false);
Dick Hollenbeck's avatar
Dick Hollenbeck committed
123 124 125
        break;

    case S_ARC:
126 127 128 129
        m_StartPointXLabel->SetLabel(_("Center X"));
        m_StartPointYLabel->SetLabel(_("Center Y"));
        m_EndPointXLabel->SetLabel(_("Start Point X"));
        m_EndPointYLabel->SetLabel(_("Start Point Y"));
130

131
        // Here the angle is a double, but the UI is still working
132 133
        // with integers
        msg << int( m_Item->GetAngle() );
Dick Hollenbeck's avatar
Dick Hollenbeck committed
134 135 136 137 138 139
        m_Angle_Ctrl->SetValue(msg);
        break;

    default:
        m_Angle_Text->Show(false);
        m_Angle_Ctrl->Show(false);
140
        m_AngleUnit->Show(false);
Dick Hollenbeck's avatar
Dick Hollenbeck committed
141
        break;
142
    }
Dick Hollenbeck's avatar
Dick Hollenbeck committed
143

144
    PutValueInLocalUnits( *m_Center_StartXCtrl, m_Item->GetStart().x );
145

146
    PutValueInLocalUnits( *m_Center_StartYCtrl, m_Item->GetStart().y );
147

148
    PutValueInLocalUnits( *m_EndX_Radius_Ctrl, m_Item->GetEnd().x );
149

150
    PutValueInLocalUnits( *m_EndY_Ctrl, m_Item->GetEnd().y );
151

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

154
    int thickness;
Dick Hollenbeck's avatar
Dick Hollenbeck committed
155

156
    if( m_Item->GetLayer() == EDGE_N )
157
        thickness =  m_brdSettings.m_EdgeSegmentWidth;
158
    else
159
        thickness =  m_brdSettings.m_DrawSegmentWidth;
Dick Hollenbeck's avatar
Dick Hollenbeck committed
160

161
    PutValueInLocalUnits( *m_DefaultThicknessCtrl, thickness );
162

163 164 165 166 167
    // Configure the layers list selector
    m_LayerSelectionCtrl->SetLayersHotkeys( false );
    m_LayerSelectionCtrl->SetLayerMask( ALL_CU_LAYERS );
    m_LayerSelectionCtrl->SetBoardFrame( m_parent );
    m_LayerSelectionCtrl->Resync();
168

169
    if( m_LayerSelectionCtrl->SetLayerSelection( m_Item->GetLayer() ) < 0 )
170
    {
171 172 173
        wxMessageBox( _("This item has an illegal layer id.\n"
                        "Now, forced on the drawings layer. Please, fix it") );
        m_LayerSelectionCtrl->SetLayerSelection( DRAW_N );
174 175 176 177 178
    }
}


/*******************************************************************/
179
void DIALOG_GRAPHIC_ITEM_PROPERTIES::OnLayerChoice( wxCommandEvent& event )
180 181
/*******************************************************************/
{
182
    int thickness;
Dick Hollenbeck's avatar
Dick Hollenbeck committed
183

184
    if( m_LayerSelectionCtrl->GetLayerSelection() == EDGE_N )
185
        thickness =  m_brdSettings.m_EdgeSegmentWidth;
186
    else
187
        thickness =  m_brdSettings.m_DrawSegmentWidth;
Dick Hollenbeck's avatar
Dick Hollenbeck committed
188

189
    PutValueInLocalUnits( *m_DefaultThicknessCtrl, thickness );
190 191 192
}

/*******************************************************************/
193
void DIALOG_GRAPHIC_ITEM_PROPERTIES::OnOkClick( wxCommandEvent& event )
194
/*******************************************************************/
charras's avatar
charras committed
195
/* Copy values in text control to the item parameters
196 197
*/
{
198
    m_parent->SaveCopyInUndoList( m_Item, UR_CHANGED );
charras's avatar
charras committed
199

200
    wxString msg;
201

Dick Hollenbeck's avatar
Dick Hollenbeck committed
202
    if( m_DC )
203
        m_Item->Draw( m_parent->GetCanvas(), m_DC, GR_XOR );
204 205

    msg = m_Center_StartXCtrl->GetValue();
206
    m_Item->SetStartX( ReturnValueFromString( g_UserUnit, msg ) );
207 208

    msg = m_Center_StartYCtrl->GetValue();
209
    m_Item->SetStartY( ReturnValueFromString( g_UserUnit, msg ) );
210 211

    msg = m_EndX_Radius_Ctrl->GetValue();
212
    m_Item->SetEndX( ReturnValueFromString( g_UserUnit, msg ) );
213 214

    msg = m_EndY_Ctrl->GetValue();
215
    m_Item->SetEndY( ReturnValueFromString( g_UserUnit, msg ) );
216 217

    msg = m_ThicknessCtrl->GetValue();
218
    m_Item->SetWidth( ReturnValueFromString( g_UserUnit, msg ) );
219 220

    msg = m_DefaultThicknessCtrl->GetValue();
221
    int thickness = ReturnValueFromString( g_UserUnit, msg );
222

223
    m_Item->SetLayer( m_LayerSelectionCtrl->GetLayerSelection() );
224

225
    if( m_Item->GetLayer() == EDGE_N )
226
         m_brdSettings.m_EdgeSegmentWidth = thickness;
227
    else
228
         m_brdSettings.m_DrawSegmentWidth = thickness;
229

Dick Hollenbeck's avatar
Dick Hollenbeck committed
230
    if( m_Item->GetShape() == S_ARC )
231
    {
Dick Hollenbeck's avatar
Dick Hollenbeck committed
232 233
        double angle;
        m_Angle_Ctrl->GetValue().ToDouble( &angle );
234
        NORMALIZE_ANGLE_360(angle);
Dick Hollenbeck's avatar
Dick Hollenbeck committed
235
        m_Item->SetAngle( angle );
236
    }
237

238
    m_parent->OnModify();
239

Dick Hollenbeck's avatar
Dick Hollenbeck committed
240
    if( m_DC )
241
        m_Item->Draw( m_parent->GetCanvas(), m_DC, GR_OR );
242

243
    m_parent->SetMsgPanel( m_Item );
244

245
    m_parent->SetDesignSettings( m_brdSettings );
Dick Hollenbeck's avatar
Dick Hollenbeck committed
246

247
    Close( true );
248 249
}

250
void DIALOG_GRAPHIC_ITEM_PROPERTIES::OnCancelClick( wxCommandEvent& event )
251
{
252
    event.Skip();
253 254
}