~pierre-parent-k/kicad/length-tunning

« back to all changes in this revision

Viewing changes to pcbnew/swap_layers.cpp

  • Committer: Pierre Parent
  • Date: 2014-07-06 10:32:13 UTC
  • mfrom: (4798.1.179 kicad)
  • Revision ID: pierre.parent@insa-rouen.fr-20140706103213-wjsdy0hc9q6wbz5v
Merge with lp:kicad 4977

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
#include <wx/statline.h>
19
19
 
20
20
 
21
 
#define LAYER_NO_CHANGE NB_LAYERS
22
 
static LAYER_NUM New_Layer[NB_PCB_LAYERS];
23
 
wxStaticText* layer_list[NB_PCB_LAYERS];
 
21
#define NO_CHANGE     LAYER_ID(-3)
24
22
 
25
23
 
26
24
enum swap_layer_id {
27
25
    ID_WINEDA_SWAPLAYERFRAME = 1800,
28
26
    ID_BUTTON_0,
29
 
    ID_TEXT_0 = ID_BUTTON_0 + NB_PCB_LAYERS
 
27
    ID_TEXT_0 = ID_BUTTON_0 + LAYER_ID_COUNT
30
28
};
31
29
 
32
30
 
33
31
class SWAP_LAYERS_DIALOG : public DIALOG_SHIM
34
32
{
 
33
public:
 
34
    SWAP_LAYERS_DIALOG( PCB_BASE_FRAME* parent, LAYER_ID* aArray );
 
35
    // ~SWAP_LAYERS_DIALOG() { };
 
36
 
35
37
private:
36
38
    PCB_BASE_FRAME*         m_Parent;
37
39
    wxBoxSizer*             OuterBoxSizer;
43
45
    wxStaticLine*           Line;
44
46
    wxStdDialogButtonSizer* StdDialogButtonSizer;
45
47
 
46
 
public:
47
 
 
48
 
    SWAP_LAYERS_DIALOG( PCB_BASE_FRAME* parent );
49
 
    ~SWAP_LAYERS_DIALOG() { };
50
 
 
51
 
private:
 
48
    LAYER_ID*               m_callers_nlayers;          // DIM() is LAYER_ID_COUNT
 
49
    wxStaticText*           layer_list[LAYER_ID_COUNT];
 
50
 
52
51
    void Sel_Layer( wxCommandEvent& event );
53
52
    void OnOkClick( wxCommandEvent& event );
54
53
    void OnCancelClick( wxCommandEvent& event );
58
57
 
59
58
 
60
59
BEGIN_EVENT_TABLE( SWAP_LAYERS_DIALOG, wxDialog )
61
 
    EVT_COMMAND_RANGE( ID_BUTTON_0, ID_BUTTON_0 + NB_PCB_LAYERS - 1,
62
 
                       wxEVT_COMMAND_BUTTON_CLICKED,
63
 
                       SWAP_LAYERS_DIALOG::Sel_Layer )
 
60
    EVT_COMMAND_RANGE( ID_BUTTON_0, ID_BUTTON_0 + LAYER_ID_COUNT - 1,
 
61
                       wxEVT_COMMAND_BUTTON_CLICKED, SWAP_LAYERS_DIALOG::Sel_Layer )
 
62
 
64
63
    EVT_BUTTON( wxID_OK, SWAP_LAYERS_DIALOG::OnOkClick )
 
64
 
65
65
    EVT_BUTTON( wxID_CANCEL, SWAP_LAYERS_DIALOG::OnCancelClick )
66
66
END_EVENT_TABLE()
67
67
 
68
68
 
69
 
SWAP_LAYERS_DIALOG::SWAP_LAYERS_DIALOG( PCB_BASE_FRAME* parent ) :
 
69
SWAP_LAYERS_DIALOG::SWAP_LAYERS_DIALOG( PCB_BASE_FRAME* parent, LAYER_ID* aArray ) :
70
70
    DIALOG_SHIM( parent, -1, _( "Swap Layers:" ), wxPoint( -1, -1 ),
71
 
                 wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER )
 
71
                 wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER ),
 
72
    m_callers_nlayers( aArray )
72
73
{
 
74
    memset( layer_list, 0, sizeof( layer_list ) );
 
75
 
73
76
    BOARD* board = parent->GetBoard();
74
77
 
75
78
    OuterBoxSizer = NULL;
113
116
    MainBoxSizer = new wxBoxSizer( wxHORIZONTAL );
114
117
    OuterBoxSizer->Add( MainBoxSizer, 1, wxGROW | wxLEFT | wxRIGHT | wxTOP, 5 );
115
118
 
116
 
    for( LAYER_NUM ii = FIRST_LAYER; ii < NB_PCB_LAYERS; ++ii )
 
119
    for( unsigned layer = 0; layer < DIM( layer_list );  ++layer )
117
120
    {
118
121
        // Provide a vertical line to separate the two FlexGrid sizers
119
 
        if( ii == 16 )
 
122
        if( layer == 32 )
120
123
        {
121
124
            Line = new wxStaticLine( this,
122
125
                                     -1,
127
130
        }
128
131
 
129
132
        // Provide a separate FlexGrid sizer for every sixteen sets of controls
130
 
        if( ii % 16 == 0 )
 
133
        if( layer % 16 == 0 )
131
134
        {
132
135
            /* Each layer has an associated static text string (to identify
133
136
             * that layer), a button (for invoking a child dialog box to
168
171
        /* Provide a text string to identify this layer (with trailing spaces
169
172
         * within that string being purged).
170
173
         */
171
 
        label = new wxStaticText( this, wxID_STATIC, board->GetLayerName( ii ),
 
174
        label = new wxStaticText( this, wxID_STATIC, board->GetLayerName( ToLAYER_ID( layer ) ),
172
175
                                  wxDefaultPosition, wxDefaultSize,
173
176
                                  wxALIGN_RIGHT );
 
177
 
174
178
        FlexColumnBoxSizer->Add( label, 0,
175
179
                                 wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL |
176
180
                                 wxLEFT | wxBOTTOM,
177
181
                                 5 );
178
182
 
179
183
        // Provide a button for this layer (which will invoke a child dialog box)
180
 
        item_ID = ID_BUTTON_0 + ii;
 
184
        item_ID = ID_BUTTON_0 + layer;
181
185
 
182
186
        Button = new wxButton( this, item_ID, wxT( "..." ), wxDefaultPosition,
183
187
                               wxSize( w, h ), 0 );
191
195
         * foreground color of the text to blue (which also indicates that the
192
196
         * layer is currently unmapped to any other layer).
193
197
         */
194
 
        item_ID = ID_TEXT_0 + ii;
 
198
        item_ID = ID_TEXT_0 + layer;
195
199
 
196
200
        /* When the first of these text strings is being added, determine
197
201
         * what size is necessary to to be able to display the longest
200
204
         * size is not this size, strings can be truncated after
201
205
         * some other layer is selected.)
202
206
         */
203
 
        if( ii == 0 )
 
207
        if( layer == 0 )
204
208
        {
205
 
            text = new wxStaticText( this, item_ID, board->GetLayerName( FIRST_LAYER ),
 
209
            text = new wxStaticText( this, item_ID, board->GetLayerName( LAYER_ID( 0 ) ),
206
210
                                     wxDefaultPosition, wxDefaultSize, 0 );
207
211
            goodSize = text->GetSize();
208
212
 
209
 
            for( LAYER_NUM jj = LAYER_N_2; jj < NB_PCB_LAYERS; ++jj )
 
213
            for( unsigned jj = 1;  jj < DIM( layer_list ); ++jj )
210
214
            {
211
 
                text->SetLabel( board->GetLayerName( jj ) );
 
215
                text->SetLabel( board->GetLayerName( ToLAYER_ID( jj ) ) );
212
216
 
213
217
                if( goodSize.x < text->GetSize().x )
214
218
                    goodSize.x = text->GetSize().x;
229
233
        FlexColumnBoxSizer->Add( text, 1,
230
234
                                 wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL |
231
235
                                 wxLEFT | wxRIGHT | wxBOTTOM, 5 );
232
 
        layer_list[ii] = text;
 
236
        layer_list[layer] = text;
233
237
    }
234
238
 
235
239
    /* Provide spacers to occupy otherwise blank cells within the second
236
240
     * FlexGrid sizer. (Becuse there are three columns, three spacers
237
241
     * are thus required for each unused row.)
238
 
     */
239
242
    for( int ii = 3 * NB_PCB_LAYERS; ii < 96; ii++ )
240
243
    {
241
244
        FlexColumnBoxSizer->Add( 5, h, 0, wxALIGN_CENTER_HORIZONTAL |
242
245
                                 wxALIGN_CENTER_VERTICAL | wxLEFT |
243
246
                                 wxRIGHT | wxBOTTOM, 5 );
244
247
    }
 
248
     */
245
249
 
246
250
    // Provide a line to separate the controls which have been provided so far
247
251
    // from the OK and Cancel buttons (which will be provided after this line)
279
283
 
280
284
    ii = event.GetId();
281
285
 
282
 
    if( ii < ID_BUTTON_0 || ii >= ID_BUTTON_0 + NB_PCB_LAYERS )
 
286
    if( ii < ID_BUTTON_0 || ii >= ID_BUTTON_0 + LAYER_ID_COUNT )
283
287
        return;
284
288
 
285
289
    ii = event.GetId() - ID_BUTTON_0;
286
290
 
287
 
    LAYER_NUM layer = New_Layer[ii];
288
 
 
289
 
    if( (layer < 0) || (layer > NB_PCB_LAYERS) )
290
 
        layer = LAYER_NO_CHANGE; // (Defaults to "No Change".)
291
 
 
292
 
    LAYER_MSK notallowed_mask = ii < NB_COPPER_LAYERS ?
293
 
                                ALL_NO_CU_LAYERS : ALL_CU_LAYERS;
294
 
    layer = m_Parent->SelectLayer( layer == LAYER_NO_CHANGE ? ii : layer,
295
 
                                   notallowed_mask );
 
291
    LAYER_ID layer = m_callers_nlayers[ii];
 
292
 
 
293
    LSET notallowed_mask = IsCopperLayer( ii ) ? LSET::AllNonCuMask() : LSET::AllCuMask();
 
294
 
 
295
    layer = m_Parent->SelectLayer( layer == NO_CHANGE ? ToLAYER_ID( ii ): layer, notallowed_mask );
296
296
 
297
297
    if( !IsValidLayer( layer ) )
298
298
        return;
299
299
 
300
 
    if( layer != New_Layer[ii] )
 
300
    if( layer != m_callers_nlayers[ii] )
301
301
    {
302
 
        New_Layer[ii] = layer;
 
302
        m_callers_nlayers[ii] = layer;
303
303
 
304
 
        if( layer >= LAYER_NO_CHANGE || layer == ii )
 
304
        if( layer == NO_CHANGE || layer == ii )
305
305
        {
306
306
            layer_list[ii]->SetLabel( _( "No Change" ) );
307
307
 
335
335
 
336
336
void PCB_EDIT_FRAME::Swap_Layers( wxCommandEvent& event )
337
337
{
338
 
    int          ii, jj;
339
 
    TRACK*       pt_segm;
340
 
    DRAWSEGMENT* pt_drawsegm;
341
 
    EDA_ITEM*    PtStruct;
342
 
 
343
 
    /* Init default values */
344
 
    for( ii = FIRST_LAYER; ii < NB_PCB_LAYERS; ii++ )
345
 
        New_Layer[ii] = LAYER_NO_CHANGE;
346
 
 
347
 
    SWAP_LAYERS_DIALOG dlg( this );
348
 
 
349
 
    ii = dlg.ShowModal();
350
 
 
351
 
    if( ii != 1 )
352
 
        return; // (Canceled dialog box returns -1 instead)
353
 
 
354
 
    /* Change traces. */
355
 
    pt_segm = GetBoard()->m_Track;
356
 
 
357
 
    for( ; pt_segm != NULL; pt_segm = pt_segm->Next() )
 
338
    LAYER_ID    new_layer[LAYER_ID_COUNT];
 
339
 
 
340
    for( unsigned i = 0; i < DIM( new_layer );  ++i )
 
341
        new_layer[i] = NO_CHANGE;
 
342
 
 
343
    SWAP_LAYERS_DIALOG dlg( this, new_layer );
 
344
 
 
345
    if( dlg.ShowModal() != 1 )
 
346
        return;     // (Canceled dialog box returns -1 instead)
 
347
 
 
348
    // Change traces.
 
349
    for( TRACK* segm = GetBoard()->m_Track;  segm;  segm = segm->Next() )
358
350
    {
359
351
        OnModify();
360
352
 
361
 
        if( pt_segm->Type() == PCB_VIA_T )
 
353
        if( segm->Type() == PCB_VIA_T )
362
354
        {
363
 
            SEGVIA* Via = (SEGVIA*) pt_segm;
 
355
            VIA* via = (VIA*) segm;
364
356
 
365
 
            if( Via->GetShape() == VIA_THROUGH )
 
357
            if( via->GetViaType() == VIA_THROUGH )
366
358
                continue;
367
359
 
368
 
            LAYER_NUM top_layer, bottom_layer;
369
 
 
370
 
            Via->LayerPair( &top_layer, &bottom_layer );
371
 
 
372
 
            if(  New_Layer[bottom_layer] >= 0 && New_Layer[bottom_layer] < LAYER_NO_CHANGE )
373
 
                bottom_layer = New_Layer[bottom_layer];
374
 
 
375
 
            if( New_Layer[top_layer] >= 0 && New_Layer[top_layer] < LAYER_NO_CHANGE )
376
 
                top_layer = New_Layer[top_layer];
377
 
 
378
 
            Via->SetLayerPair( top_layer, bottom_layer );
 
360
            LAYER_ID top_layer, bottom_layer;
 
361
 
 
362
            via->LayerPair( &top_layer, &bottom_layer );
 
363
 
 
364
            if( new_layer[bottom_layer] != NO_CHANGE )
 
365
                bottom_layer = new_layer[bottom_layer];
 
366
 
 
367
            if( new_layer[top_layer] != NO_CHANGE )
 
368
                top_layer = new_layer[top_layer];
 
369
 
 
370
            via->SetLayerPair( top_layer, bottom_layer );
379
371
        }
380
372
        else
381
373
        {
382
 
            jj = pt_segm->GetLayer();
 
374
            int jj = segm->GetLayer();
383
375
 
384
 
            if( New_Layer[jj] >= 0 && New_Layer[jj] < LAYER_NO_CHANGE )
385
 
                pt_segm->SetLayer( New_Layer[jj] );
 
376
            if( new_layer[jj] != NO_CHANGE )
 
377
                segm->SetLayer( new_layer[jj] );
386
378
        }
387
379
    }
388
380
 
389
 
    /* Change zones. */
390
 
    for( pt_segm = GetBoard()->m_Zone;  pt_segm;  pt_segm = pt_segm->Next() )
 
381
    // Change zones.
 
382
    for( TRACK* segm = GetBoard()->m_Zone;  segm;  segm = segm->Next() )
391
383
    {
392
384
        OnModify();
393
 
        jj = pt_segm->GetLayer();
 
385
        int jj = segm->GetLayer();
394
386
 
395
 
        if( New_Layer[jj] >= 0 && New_Layer[jj] < LAYER_NO_CHANGE )
396
 
            pt_segm->SetLayer( New_Layer[jj] );
 
387
        if( new_layer[jj] != NO_CHANGE )
 
388
            segm->SetLayer( new_layer[jj] );
397
389
    }
398
390
 
399
 
    /* Change other segments. */
400
 
    PtStruct = GetBoard()->m_Drawings;
401
 
 
402
 
    for( ; PtStruct != NULL; PtStruct = PtStruct->Next() )
 
391
    // Change other segments.
 
392
    for( EDA_ITEM* item = GetBoard()->m_Drawings; item; item = item->Next() )
403
393
    {
404
 
        if( PtStruct->Type() == PCB_LINE_T )
 
394
        if( item->Type() == PCB_LINE_T )
405
395
        {
406
396
            OnModify();
407
 
            pt_drawsegm = (DRAWSEGMENT*) PtStruct;
408
 
            jj = pt_drawsegm->GetLayer();
409
 
 
410
 
            if( New_Layer[jj] >= 0 && New_Layer[jj] < LAYER_NO_CHANGE )
411
 
                pt_drawsegm->SetLayer( New_Layer[jj] );
 
397
 
 
398
            DRAWSEGMENT* drawsegm = (DRAWSEGMENT*) item;
 
399
            int jj = drawsegm->GetLayer();
 
400
 
 
401
            if( new_layer[jj] != NO_CHANGE )
 
402
                drawsegm->SetLayer( new_layer[jj] );
412
403
        }
413
404
    }
414
405