dialog_graphic_item_properties_for_Modedit.cpp 6.97 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/**
 @file dialog_graphic_item_properties_for_Modedit.cpp
 */

/* Edit parameters values of graphic items in a footprint body:
 * Lines
 * Circles
 * Arcs
 * used as graphic elements found on non copper layers in boards
 * Footprint texts are not always graphic items and are not handled here
 */
#include <fctsys.h>
#include <macros.h>
#include <confirm.h>
#include <class_drawpanel.h>
#include <pcbnew.h>
#include <wxPcbStruct.h>
#include <class_board_design_settings.h>
#include <module_editor_frame.h>
20
#include <base_units.h>
21 22 23 24 25 26

#include <class_board.h>
#include <class_module.h>
#include <class_edge_mod.h>

#include <dialog_graphic_item_properties_base.h>
27
#include <class_pcb_layer_box_selector.h>
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83

class DIALOG_MODEDIT_FP_BODY_ITEM_PROPERTIES: public DIALOG_GRAPHIC_ITEM_PROPERTIES_BASE
{
private:
    FOOTPRINT_EDIT_FRAME* m_parent;
    EDGE_MODULE* m_item;
    BOARD_DESIGN_SETTINGS  m_brdSettings;
    MODULE * m_module;

public:
    DIALOG_MODEDIT_FP_BODY_ITEM_PROPERTIES( FOOTPRINT_EDIT_FRAME* aParent,
                                            EDGE_MODULE * aItem);
    ~DIALOG_MODEDIT_FP_BODY_ITEM_PROPERTIES() {};

private:
    void initDlg( );
    void OnOkClick( wxCommandEvent& event );
    void OnCancelClick( wxCommandEvent& event ){ event.Skip(); }
    void OnLayerChoice( wxCommandEvent& event );
};

DIALOG_MODEDIT_FP_BODY_ITEM_PROPERTIES::DIALOG_MODEDIT_FP_BODY_ITEM_PROPERTIES(
                                                        FOOTPRINT_EDIT_FRAME* aParent,
                                                        EDGE_MODULE * aItem ):
    DIALOG_GRAPHIC_ITEM_PROPERTIES_BASE( aParent )
{
    m_parent = aParent;
    m_item = aItem;
    m_brdSettings = m_parent->GetDesignSettings();
    m_module = m_parent->GetBoard()->m_Modules;
    initDlg();
    Layout();
    GetSizer()->SetSizeHints( this );
    Centre();
}

/*
 * Dialog to edit a graphic item of a footprint body.
 */
void FOOTPRINT_EDIT_FRAME::InstallFootprintBodyItemPropertiesDlg(EDGE_MODULE * aItem)
{
    if ( aItem == NULL )
    {
        wxMessageBox( wxT("InstallGraphicItemPropertiesDialog() error: NULL item"));
        return;
    }

    m_canvas->SetIgnoreMouseEvents( true );
    DIALOG_MODEDIT_FP_BODY_ITEM_PROPERTIES* dialog =
        new DIALOG_MODEDIT_FP_BODY_ITEM_PROPERTIES( this, aItem );
    dialog->ShowModal();
    dialog->Destroy();
    m_canvas->MoveCursorToCrossHair();
    m_canvas->SetIgnoreMouseEvents( false );
}

Dick Hollenbeck's avatar
Dick Hollenbeck committed
84

85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
void DIALOG_MODEDIT_FP_BODY_ITEM_PROPERTIES::initDlg()
{
    SetFocus();
    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;
Dick Hollenbeck's avatar
Dick Hollenbeck committed
106

107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
        texts_unit[ii]->SetLabel( GetAbbreviatedUnitsLabel() );
    }

    wxString msg;

    // Change texts according to the segment shape:
    switch ( m_item->GetShape() )
    {
    case S_CIRCLE:
        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);
        break;

    case S_ARC:
        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() );
134 135 136 137 138 139 140 141 142 143
        m_Angle_Ctrl->SetValue(msg);
        break;

    default:
        m_Angle_Text->Show(false);
        m_Angle_Ctrl->Show(false);
        m_AngleUnit->Show(false);
        break;
    }

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() );
153

154
    PutValueInLocalUnits( *m_DefaultThicknessCtrl, m_brdSettings.m_ModuleSegmentWidth );
155

156 157
    // Configure the layers list selector
    m_LayerSelectionCtrl->SetLayersHotkeys( false );
Dick Hollenbeck's avatar
Dick Hollenbeck committed
158
    m_LayerSelectionCtrl->SetLayerSet( LSET::InternalCuMask().set( Edge_Cuts ) );
159 160
    m_LayerSelectionCtrl->SetBoardFrame( m_parent );
    m_LayerSelectionCtrl->Resync();
Dick Hollenbeck's avatar
Dick Hollenbeck committed
161

162
    if( m_LayerSelectionCtrl->SetLayerSelection( m_item->GetLayer() ) < 0 )
163
    {
Dick Hollenbeck's avatar
Dick Hollenbeck committed
164 165 166
        wxMessageBox( _( "This item has an illegal layer id.\n"
                        "Now, forced on the front silk screen layer. Please, fix it" ) );
        m_LayerSelectionCtrl->SetLayerSelection( F_SilkS );
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
    }
}


/*******************************************************************/
void DIALOG_MODEDIT_FP_BODY_ITEM_PROPERTIES::OnLayerChoice( wxCommandEvent& event )
/*******************************************************************/
{
}

/*******************************************************************/
void DIALOG_MODEDIT_FP_BODY_ITEM_PROPERTIES::OnOkClick( wxCommandEvent& event )
/*******************************************************************/
/* Copy values in text control to the item parameters
*/
{
183
    LAYER_NUM layer = m_LayerSelectionCtrl->GetLayerSelection();
184

185
    if( IsCopperLayer( layer ) )
186
    {
187 188
        /* an edge is put on a copper layer: this it is very dangerous. a
         * confirmation is requested */
189 190 191 192 193 194
        if( !IsOK( NULL,
                   _( "The graphic item will be on a copper layer. This is very dangerous. Are you sure?" ) ) )
            return;
    }

    m_parent->SaveCopyInUndoList( m_module, UR_MODEDIT );
195
    m_module->SetLastEditTime();
196 197 198

    wxString msg;

199
    wxPoint coord;
200

201
    msg = m_Center_StartXCtrl->GetValue();
202
    coord.x = ValueFromString( g_UserUnit, msg );
203
    msg = m_Center_StartYCtrl->GetValue();
204
    coord.y = ValueFromString( g_UserUnit, msg );
205 206
    m_item->SetStart( coord );
    m_item->SetStart0( coord );
207 208

    msg = m_EndX_Radius_Ctrl->GetValue();
209
    coord.x = ValueFromString( g_UserUnit, msg );
210
    msg = m_EndY_Ctrl->GetValue();
211
    coord.y = ValueFromString( g_UserUnit, msg );
212 213
    m_item->SetEnd( coord );
    m_item->SetEnd0( coord );
214 215

    msg = m_ThicknessCtrl->GetValue();
216
    m_item->SetWidth( ValueFromString( g_UserUnit, msg ) );
217 218

    msg = m_DefaultThicknessCtrl->GetValue();
219
    int thickness = ValueFromString( g_UserUnit, msg );
220 221 222
    m_brdSettings.m_ModuleSegmentWidth = thickness;
    m_parent->SetDesignSettings( m_brdSettings );

Dick Hollenbeck's avatar
Dick Hollenbeck committed
223
    m_item->SetLayer( ToLAYER_ID( layer ) );
224 225 226 227 228 229 230 231 232 233

    if( m_item->GetShape() == S_ARC )
    {
        double angle;
        m_Angle_Ctrl->GetValue().ToDouble( &angle );
        NORMALIZE_ANGLE_360(angle);
        m_item->SetAngle( angle );
    }

    m_parent->OnModify();
234
    m_parent->SetMsgPanel( m_item );
235 236 237

    Close( true );
}