18
18
#include <wx/statline.h>
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)
26
24
enum swap_layer_id {
27
25
ID_WINEDA_SWAPLAYERFRAME = 1800,
29
ID_TEXT_0 = ID_BUTTON_0 + NB_PCB_LAYERS
27
ID_TEXT_0 = ID_BUTTON_0 + LAYER_ID_COUNT
33
31
class SWAP_LAYERS_DIALOG : public DIALOG_SHIM
34
SWAP_LAYERS_DIALOG( PCB_BASE_FRAME* parent, LAYER_ID* aArray );
35
// ~SWAP_LAYERS_DIALOG() { };
36
38
PCB_BASE_FRAME* m_Parent;
37
39
wxBoxSizer* OuterBoxSizer;
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 )
64
63
EVT_BUTTON( wxID_OK, SWAP_LAYERS_DIALOG::OnOkClick )
65
65
EVT_BUTTON( wxID_CANCEL, SWAP_LAYERS_DIALOG::OnCancelClick )
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 )
74
memset( layer_list, 0, sizeof( layer_list ) );
73
76
BOARD* board = parent->GetBoard();
75
78
OuterBoxSizer = NULL;
168
171
/* Provide a text string to identify this layer (with trailing spaces
169
172
* within that string being purged).
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,
174
178
FlexColumnBoxSizer->Add( label, 0,
175
179
wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL |
176
180
wxLEFT | wxBOTTOM,
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;
182
186
Button = new wxButton( this, item_ID, wxT( "..." ), wxDefaultPosition,
183
187
wxSize( w, h ), 0 );
200
204
* size is not this size, strings can be truncated after
201
205
* some other layer is selected.)
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();
209
for( LAYER_NUM jj = LAYER_N_2; jj < NB_PCB_LAYERS; ++jj )
213
for( unsigned jj = 1; jj < DIM( layer_list ); ++jj )
211
text->SetLabel( board->GetLayerName( jj ) );
215
text->SetLabel( board->GetLayerName( ToLAYER_ID( jj ) ) );
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;
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.)
239
242
for( int ii = 3 * NB_PCB_LAYERS; ii < 96; ii++ )
241
244
FlexColumnBoxSizer->Add( 5, h, 0, wxALIGN_CENTER_HORIZONTAL |
242
245
wxALIGN_CENTER_VERTICAL | wxLEFT |
243
246
wxRIGHT | wxBOTTOM, 5 );
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)
280
284
ii = event.GetId();
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 )
285
289
ii = event.GetId() - ID_BUTTON_0;
287
LAYER_NUM layer = New_Layer[ii];
289
if( (layer < 0) || (layer > NB_PCB_LAYERS) )
290
layer = LAYER_NO_CHANGE; // (Defaults to "No Change".)
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,
291
LAYER_ID layer = m_callers_nlayers[ii];
293
LSET notallowed_mask = IsCopperLayer( ii ) ? LSET::AllNonCuMask() : LSET::AllCuMask();
295
layer = m_Parent->SelectLayer( layer == NO_CHANGE ? ToLAYER_ID( ii ): layer, notallowed_mask );
297
297
if( !IsValidLayer( layer ) )
300
if( layer != New_Layer[ii] )
300
if( layer != m_callers_nlayers[ii] )
302
New_Layer[ii] = layer;
302
m_callers_nlayers[ii] = layer;
304
if( layer >= LAYER_NO_CHANGE || layer == ii )
304
if( layer == NO_CHANGE || layer == ii )
306
306
layer_list[ii]->SetLabel( _( "No Change" ) );
336
336
void PCB_EDIT_FRAME::Swap_Layers( wxCommandEvent& event )
340
DRAWSEGMENT* pt_drawsegm;
343
/* Init default values */
344
for( ii = FIRST_LAYER; ii < NB_PCB_LAYERS; ii++ )
345
New_Layer[ii] = LAYER_NO_CHANGE;
347
SWAP_LAYERS_DIALOG dlg( this );
349
ii = dlg.ShowModal();
352
return; // (Canceled dialog box returns -1 instead)
355
pt_segm = GetBoard()->m_Track;
357
for( ; pt_segm != NULL; pt_segm = pt_segm->Next() )
338
LAYER_ID new_layer[LAYER_ID_COUNT];
340
for( unsigned i = 0; i < DIM( new_layer ); ++i )
341
new_layer[i] = NO_CHANGE;
343
SWAP_LAYERS_DIALOG dlg( this, new_layer );
345
if( dlg.ShowModal() != 1 )
346
return; // (Canceled dialog box returns -1 instead)
349
for( TRACK* segm = GetBoard()->m_Track; segm; segm = segm->Next() )
361
if( pt_segm->Type() == PCB_VIA_T )
353
if( segm->Type() == PCB_VIA_T )
363
SEGVIA* Via = (SEGVIA*) pt_segm;
355
VIA* via = (VIA*) segm;
365
if( Via->GetShape() == VIA_THROUGH )
357
if( via->GetViaType() == VIA_THROUGH )
368
LAYER_NUM top_layer, bottom_layer;
370
Via->LayerPair( &top_layer, &bottom_layer );
372
if( New_Layer[bottom_layer] >= 0 && New_Layer[bottom_layer] < LAYER_NO_CHANGE )
373
bottom_layer = New_Layer[bottom_layer];
375
if( New_Layer[top_layer] >= 0 && New_Layer[top_layer] < LAYER_NO_CHANGE )
376
top_layer = New_Layer[top_layer];
378
Via->SetLayerPair( top_layer, bottom_layer );
360
LAYER_ID top_layer, bottom_layer;
362
via->LayerPair( &top_layer, &bottom_layer );
364
if( new_layer[bottom_layer] != NO_CHANGE )
365
bottom_layer = new_layer[bottom_layer];
367
if( new_layer[top_layer] != NO_CHANGE )
368
top_layer = new_layer[top_layer];
370
via->SetLayerPair( top_layer, bottom_layer );
382
jj = pt_segm->GetLayer();
374
int jj = segm->GetLayer();
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] );
390
for( pt_segm = GetBoard()->m_Zone; pt_segm; pt_segm = pt_segm->Next() )
382
for( TRACK* segm = GetBoard()->m_Zone; segm; segm = segm->Next() )
393
jj = pt_segm->GetLayer();
385
int jj = segm->GetLayer();
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] );
399
/* Change other segments. */
400
PtStruct = GetBoard()->m_Drawings;
402
for( ; PtStruct != NULL; PtStruct = PtStruct->Next() )
391
// Change other segments.
392
for( EDA_ITEM* item = GetBoard()->m_Drawings; item; item = item->Next() )
404
if( PtStruct->Type() == PCB_LINE_T )
394
if( item->Type() == PCB_LINE_T )
407
pt_drawsegm = (DRAWSEGMENT*) PtStruct;
408
jj = pt_drawsegm->GetLayer();
410
if( New_Layer[jj] >= 0 && New_Layer[jj] < LAYER_NO_CHANGE )
411
pt_drawsegm->SetLayer( New_Layer[jj] );
398
DRAWSEGMENT* drawsegm = (DRAWSEGMENT*) item;
399
int jj = drawsegm->GetLayer();
401
if( new_layer[jj] != NO_CHANGE )
402
drawsegm->SetLayer( new_layer[jj] );