dialog_global_edit_tracks_and_vias.cpp 7.09 KB
Newer Older
1 2 3 4 5 6 7
/////////////////////////////////////////////////////////////////////////////
// Name:        dialog_global_edit_tracks_and_vias.cpp
// Author:      jean-pierre Charras
// Created:     30 oct 2009
// Licence:     GPL
/////////////////////////////////////////////////////////////////////////////

8 9 10 11 12
#include <fctsys.h>
#include <confirm.h>
#include <pcbnew.h>
#include <wxPcbStruct.h>
#include <class_drawpanel.h>
13
#include <base_units.h>
14

15
#include <class_board.h>
16

17
#include <dialog_global_edit_tracks_and_vias.h>
18

19

20
/**
21
 *  DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS, derived from DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS_BASE_BASE
22 23 24 25
 *  @see dialog_global_edit_tracks_and_vias_base.h and dialog_global_edit_tracks_and_vias_base.cpp,
 *  automatically created by wxFormBuilder
 */

26 27
DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS::DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS( PCB_EDIT_FRAME* aParent,
                                                                        int             aNetcode ) :
28 29 30 31
    DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS_BASE( aParent )
{
    m_Parent  = aParent;
    m_Netcode = aNetcode;
32
    m_OptionID = 0;
33 34
    MyInit();
    GetSizer()->SetSizeHints( this );
35
    Layout();
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
}


/*************************************************/
void DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS::MyInit()
/*************************************************/
{
    SetFocus();

    wxString      msg;

    // Display current setup for tracks and vias
    BOARD*        board = m_Parent->GetBoard();
    NETCLASSES&   netclasses = board->m_NetClasses;
    NETINFO_ITEM* net = board->FindNet( m_Netcode );
    NETCLASS*     netclass = netclasses.GetDefault();
52

53 54 55
    if( net )
    {
        m_CurrentNetName->SetLabel( net->GetNetname() );
56 57
        m_CurrentNetclassName->SetLabel( board->GetCurrentNetClassName() );
        netclass = netclasses.Find( board->GetCurrentNetClassName() );
58 59
    }

60 61 62
    /* Disable the option "copy current to net" if we have only default netclass values
     * i.e. when m_TrackWidthSelector and m_ViaSizeSelector are set to 0
     */
63
    if( !board->GetTrackWidthIndex() && !board->GetViaSizeIndex() )
64
    {
charras's avatar
charras committed
65
        m_Net2CurrValueButton->Enable( false );
66 67 68 69 70 71 72
        m_OptionID = ID_NETCLASS_VALUES_TO_CURRENT_NET;
        m_NetUseNetclassValueButton->SetValue(true);
    }
    else
     {
        m_OptionID = ID_CURRENT_VALUES_TO_CURRENT_NET;
        m_Net2CurrValueButton->SetValue(true);
73 74 75
    }

    // Display current values, and current netclass values:
76
    int value = netclass->GetTrackWidth();      // Display track width
77
    msg = ReturnStringFromValue( g_UserUnit, value, true );
78
    m_gridDisplayCurrentSettings->SetCellValue( 0, 0, msg  );
79 80

    if( board->GetTrackWidthIndex() )
81 82
    {
        value = board->GetCurrentTrackWidth();
83
        msg   = ReturnStringFromValue( g_UserUnit, value, true );
84 85 86
    }
    else
        msg = _( "Default" );
87

88
    m_gridDisplayCurrentSettings->SetCellValue( 1, 0, msg  );
charras's avatar
charras committed
89

90
    value = netclass->GetViaDiameter();      // Display via diameter
91
    msg   = ReturnStringFromValue( g_UserUnit, value, true );
92
    m_gridDisplayCurrentSettings->SetCellValue( 0, 1, msg  );
93 94

    if( board->GetViaSizeIndex() )
95 96
    {
        value = board->GetCurrentViaSize();
97
        msg   = ReturnStringFromValue( g_UserUnit, value, true );
98 99 100 101 102
    }
    else
        msg = _( "Default" );
    m_gridDisplayCurrentSettings->SetCellValue( 1, 1, msg  );

103
    value = netclass->GetViaDrill();      // Display via drill
104
    msg   = ReturnStringFromValue( g_UserUnit, value, true );
105 106 107
    m_gridDisplayCurrentSettings->SetCellValue( 0, 2, msg  );
    value = board->GetCurrentViaDrill();
    if( value >= 0 )
108
        msg = ReturnStringFromValue( g_UserUnit, value, true );
109 110 111 112
    else
        msg = _( "Default" );
    m_gridDisplayCurrentSettings->SetCellValue( 1, 2, msg  );

113
    value = netclass->GetuViaDiameter();      // Display micro via diameter
114
    msg   = ReturnStringFromValue( g_UserUnit, value, true );
115 116 117
    m_gridDisplayCurrentSettings->SetCellValue( 0, 3, msg  );
#if 0   // Currently we use always the default netclass value
    value = board->GetCurrentMicroViaSize();
118
    msg   = ReturnStringFromValue( g_UserUnit, value, true );
119 120 121 122
#endif
    msg = _( "Default" );
    m_gridDisplayCurrentSettings->SetCellValue( 1, 3, msg  );

123
    value = netclass->GetuViaDrill();      // Display micro via drill
124
    msg   = ReturnStringFromValue( g_UserUnit, value, true );
125 126 127 128
    m_gridDisplayCurrentSettings->SetCellValue( 0, 4, msg  );
#if 0   // Currently we use always the default netclass value
    value = board->GetCurrentMicroViaDrill();
    if( value >= 0 )
129
        msg = ReturnStringFromValue( g_UserUnit, value, true );
130 131 132 133 134
    else
#endif
    msg = _( "Default" );
    m_gridDisplayCurrentSettings->SetCellValue( 1, 4, msg  );

135
    // Set all cells Read Only
136 137 138 139 140
    for( int ii = 0; ii < m_gridDisplayCurrentSettings->GetNumberRows(); ii++ )
    {
        for( int jj = 0; jj < m_gridDisplayCurrentSettings->GetNumberCols(); jj++ )
            m_gridDisplayCurrentSettings->SetReadOnly( ii, jj, true );
    }
141

142 143
    // needs wxWidgets version >= 2.8.8:
    m_gridDisplayCurrentSettings->SetRowLabelSize(wxGRID_AUTOSIZE);
144

charras's avatar
charras committed
145
    m_gridDisplayCurrentSettings->Fit();
146 147 148 149 150 151 152 153
}


/*******************************************************************/
void DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS::OnOkClick( wxCommandEvent& event )
/*******************************************************************/
{
    bool change = false;
charras's avatar
charras committed
154

155
    switch( m_OptionID )
156
    {
charras's avatar
charras committed
157 158 159 160 161 162
    case ID_CURRENT_VALUES_TO_CURRENT_NET:
        if( !IsOK( this,
                  _( "Set current Net tracks and vias sizes and drill to the current values?" ) ) )
            return;
        {
            wxBusyCursor dummy;
163
            change = m_Parent->Change_Net_Tracks_And_Vias_Sizes( m_Netcode, false );
charras's avatar
charras committed
164 165 166 167 168 169 170 171 172 173
        }
        break;

    case ID_NETCLASS_VALUES_TO_CURRENT_NET:
        if( !IsOK( this,
                  _(
                      "Set current Net tracks and vias sizes and drill to the Netclass default value?" ) ) )
            return;
        {
            wxBusyCursor dummy;
174
            change = m_Parent->Change_Net_Tracks_And_Vias_Sizes( m_Netcode, true );
charras's avatar
charras committed
175 176 177 178 179 180 181 182
        }
        break;

    case ID_ALL_TRACKS_VIAS:
        if( !IsOK( this, _( "Set All Tracks and Vias to Netclass value" ) ) )
            return;
        {
            wxBusyCursor dummy;
183
            change = m_Parent->Reset_All_Tracks_And_Vias_To_Netclass_Values( true, true );
charras's avatar
charras committed
184 185 186 187 188 189 190 191
        }
        break;

    case ID_ALL_VIAS:
        if( !IsOK( this, _( "Set All Via to Netclass value" ) ) )
            return;
        {
            wxBusyCursor dummy;
192
            change = m_Parent->Reset_All_Tracks_And_Vias_To_Netclass_Values( false, true );
charras's avatar
charras committed
193 194 195 196 197 198 199 200
        }
        break;

    case ID_ALL_TRACKS:
        if( !IsOK( this, _( "Set All Track to Netclass value" ) ) )
            return;
        {
            wxBusyCursor dummy;
201
            change = m_Parent->Reset_All_Tracks_And_Vias_To_Netclass_Values( true, false );
charras's avatar
charras committed
202 203
        }
        break;
204 205 206
    }

    EndModal( 1 );
207

208
    if( change )
209
        m_Parent->GetCanvas()->Refresh();
210 211 212 213 214 215 216 217 218 219
}


/*******************************
 *event handler for wxID_CANCEL
 ******************************/
void DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS::OnCancelClick( wxCommandEvent& event )
{
    EndModal( 0 );
}