2012-05-04 17:44:42 +00:00
|
|
|
/**
|
2012-12-18 13:54:44 +00:00
|
|
|
* @file dialog_select_one_pcb_layer.cpp
|
2012-05-04 17:44:42 +00:00
|
|
|
* @brief Set up a dialog to choose a PCB Layer.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <fctsys.h>
|
|
|
|
#include <gerbview_frame.h>
|
|
|
|
#include <select_layers_to_pcb.h>
|
|
|
|
|
|
|
|
// Exported function
|
2013-03-31 13:27:46 +00:00
|
|
|
const wxString GetPCBDefaultLayerName( LAYER_NUM aLayerNumber );
|
2012-05-04 17:44:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
enum layer_sel_id {
|
|
|
|
ID_LAYER_SELECT_TOP = 1800,
|
|
|
|
ID_LAYER_SELECT_BOTTOM,
|
|
|
|
ID_LAYER_SELECT
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class SELECT_LAYER_DIALOG : public wxDialog
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
GERBVIEW_FRAME* m_Parent;
|
|
|
|
wxRadioBox* m_LayerList;
|
2013-03-31 13:27:46 +00:00
|
|
|
LAYER_NUM m_LayerId[int(NB_LAYERS) + 1]; // One extra element for "(Deselect)" radiobutton
|
2012-05-04 17:44:42 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
// Constructor and destructor
|
2013-03-31 13:27:46 +00:00
|
|
|
SELECT_LAYER_DIALOG( GERBVIEW_FRAME* parent, LAYER_NUM aDefaultLayer,
|
2012-05-04 17:44:42 +00:00
|
|
|
int aCopperLayerCount, bool aShowDeselectOption );
|
|
|
|
~SELECT_LAYER_DIALOG() { };
|
|
|
|
|
|
|
|
private:
|
|
|
|
void OnLayerSelected( wxCommandEvent& event );
|
|
|
|
void OnCancelClick( wxCommandEvent& event );
|
|
|
|
|
|
|
|
DECLARE_EVENT_TABLE()
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
BEGIN_EVENT_TABLE( SELECT_LAYER_DIALOG, wxDialog )
|
|
|
|
EVT_BUTTON( wxID_OK, SELECT_LAYER_DIALOG::OnLayerSelected )
|
|
|
|
EVT_BUTTON( wxID_CANCEL, SELECT_LAYER_DIALOG::OnCancelClick )
|
|
|
|
EVT_RADIOBOX( ID_LAYER_SELECT, SELECT_LAYER_DIALOG::OnLayerSelected )
|
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
|
|
|
|
/** Install the dialog box for layer selection
|
|
|
|
* @param aDefaultLayer = Preselection (NB_LAYERS for "(Deselect)" layer)
|
|
|
|
* @param aCopperLayerCount = number of copper layers
|
|
|
|
* @param aShowDeselectOption = display a "(Deselect)" radiobutton (when set to true)
|
|
|
|
* @return new layer value (NB_LAYERS when "(Deselect)" radiobutton selected),
|
|
|
|
* or -1 if canceled
|
|
|
|
*
|
|
|
|
* Providing the option to also display a "(Deselect)" radiobutton makes the
|
|
|
|
* GerbView's "Export to Pcbnew" command) more "user friendly",
|
|
|
|
* by permitting any layer to be "deselected" immediately after its
|
|
|
|
* corresponding radiobutton has been clicked on. (It would otherwise be
|
|
|
|
* necessary to first cancel the "Select Layer:" dialog box (invoked after a
|
|
|
|
* different radiobutton is clicked on) prior to then clicking on the "Deselect"
|
|
|
|
* button provided within the "Layer selection:" dialog box).
|
|
|
|
*/
|
2013-04-10 07:03:19 +00:00
|
|
|
LAYER_NUM GERBVIEW_FRAME::SelectPCBLayer( LAYER_NUM aDefaultLayer, int aCopperLayerCount,
|
|
|
|
bool aShowDeselectOption )
|
2012-05-04 17:44:42 +00:00
|
|
|
{
|
2013-03-31 13:27:46 +00:00
|
|
|
LAYER_NUM layer;
|
2012-05-04 17:44:42 +00:00
|
|
|
SELECT_LAYER_DIALOG* frame = new SELECT_LAYER_DIALOG( this, aDefaultLayer,
|
|
|
|
aCopperLayerCount,
|
|
|
|
aShowDeselectOption );
|
|
|
|
|
|
|
|
layer = frame->ShowModal();
|
|
|
|
frame->Destroy();
|
|
|
|
return layer;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The "OK" and "Cancel" buttons are positioned (in a horizontal line)
|
|
|
|
* beneath the "Layer" radiobox, unless that contains only one column of
|
|
|
|
* radiobuttons, in which case they are positioned (in a vertical line)
|
|
|
|
* to the right of that radiobox.
|
|
|
|
*/
|
|
|
|
SELECT_LAYER_DIALOG::SELECT_LAYER_DIALOG( GERBVIEW_FRAME* parent,
|
2013-03-31 13:27:46 +00:00
|
|
|
LAYER_NUM aDefaultLayer, int aCopperLayerCount,
|
2012-05-04 17:44:42 +00:00
|
|
|
bool aShowDeselectOption ) :
|
|
|
|
wxDialog( parent, -1, _( "Select Layer:" ), wxPoint( -1, -1 ),
|
|
|
|
wxSize( 470, 250 ),
|
2013-11-15 09:28:31 +00:00
|
|
|
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER )
|
2012-05-04 17:44:42 +00:00
|
|
|
{
|
|
|
|
wxButton* Button;
|
2013-03-31 13:27:46 +00:00
|
|
|
LAYER_NUM ii;
|
2013-04-10 07:03:19 +00:00
|
|
|
wxString LayerList[NB_PCB_LAYERS + 1]; // One extra element for "(Deselect)"
|
2012-05-04 17:44:42 +00:00
|
|
|
// radiobutton
|
|
|
|
int LayerCount, LayerSelect = -1;
|
|
|
|
|
|
|
|
m_Parent = parent;
|
|
|
|
|
|
|
|
// Build the layer list; first build copper layers list
|
|
|
|
LayerCount = 0;
|
2013-03-31 13:27:46 +00:00
|
|
|
for( ii = FIRST_COPPER_LAYER; ii < NB_COPPER_LAYERS; ++ii )
|
2012-05-04 17:44:42 +00:00
|
|
|
{
|
2013-03-31 13:27:46 +00:00
|
|
|
m_LayerId[ii] = FIRST_LAYER;
|
2012-05-04 17:44:42 +00:00
|
|
|
|
2013-03-31 13:27:46 +00:00
|
|
|
if( ii == FIRST_COPPER_LAYER || ii == LAST_COPPER_LAYER || ii < aCopperLayerCount-1 )
|
2012-05-04 17:44:42 +00:00
|
|
|
{
|
|
|
|
LayerList[LayerCount] = GetPCBDefaultLayerName( ii );
|
|
|
|
|
|
|
|
if( ii == aDefaultLayer )
|
|
|
|
LayerSelect = LayerCount;
|
|
|
|
|
|
|
|
m_LayerId[LayerCount] = ii;
|
|
|
|
LayerCount++;
|
|
|
|
}
|
|
|
|
}
|
2013-04-10 07:03:19 +00:00
|
|
|
// Build the layer list; build non copper layers list
|
|
|
|
for( ; ii < NB_PCB_LAYERS; ++ii )
|
2012-05-04 17:44:42 +00:00
|
|
|
{
|
2013-03-31 13:27:46 +00:00
|
|
|
m_LayerId[ii] = FIRST_LAYER;
|
2012-05-04 17:44:42 +00:00
|
|
|
|
|
|
|
LayerList[LayerCount] = GetPCBDefaultLayerName( ii );
|
|
|
|
|
|
|
|
if( ii == aDefaultLayer )
|
|
|
|
LayerSelect = LayerCount;
|
|
|
|
|
|
|
|
m_LayerId[LayerCount] = ii;
|
|
|
|
LayerCount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// When appropriate, also provide a "(Deselect)" radiobutton
|
|
|
|
if( aShowDeselectOption )
|
|
|
|
{
|
|
|
|
LayerList[LayerCount] = _( "(Deselect)" );
|
|
|
|
|
2013-03-31 13:27:46 +00:00
|
|
|
if( NB_PCB_LAYERS == aDefaultLayer )
|
2012-05-04 17:44:42 +00:00
|
|
|
LayerSelect = LayerCount;
|
|
|
|
|
2013-03-31 13:27:46 +00:00
|
|
|
m_LayerId[LayerCount] = NB_PCB_LAYERS;
|
2012-05-04 17:44:42 +00:00
|
|
|
LayerCount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_LayerList = new wxRadioBox( this, ID_LAYER_SELECT, _( "Layer" ),
|
|
|
|
wxPoint( -1, -1 ), wxSize( -1, -1 ),
|
|
|
|
LayerCount, LayerList,
|
|
|
|
(LayerCount < 8) ? LayerCount : 8,
|
|
|
|
wxRA_SPECIFY_ROWS );
|
|
|
|
|
|
|
|
if( LayerSelect >= 0 )
|
|
|
|
m_LayerList->SetSelection( LayerSelect );
|
|
|
|
|
|
|
|
wxBoxSizer* FrameBoxSizer = new wxBoxSizer( wxHORIZONTAL );
|
|
|
|
SetSizer( FrameBoxSizer );
|
|
|
|
FrameBoxSizer->Add( m_LayerList, 0, wxALIGN_TOP | wxALL, 5 );
|
|
|
|
wxBoxSizer* ButtonBoxSizer = new wxBoxSizer( wxVERTICAL );
|
|
|
|
FrameBoxSizer->Add( ButtonBoxSizer, 0, wxALIGN_BOTTOM | wxALL, 0 );
|
|
|
|
|
|
|
|
Button = new wxButton( this, wxID_OK, _( "OK" ) );
|
|
|
|
Button->SetDefault();
|
|
|
|
ButtonBoxSizer->Add( Button, 0, wxGROW | wxALL, 5 );
|
|
|
|
|
|
|
|
Button = new wxButton( this, wxID_CANCEL, _( "Cancel" ) );
|
|
|
|
ButtonBoxSizer->Add( Button, 0, wxGROW | wxALL, 5 );
|
|
|
|
|
|
|
|
SetFocus();
|
|
|
|
|
|
|
|
GetSizer()->SetSizeHints( this );
|
|
|
|
|
|
|
|
Center();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SELECT_LAYER_DIALOG::OnLayerSelected( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
int ii = m_LayerId[m_LayerList->GetSelection()];
|
|
|
|
|
|
|
|
EndModal( ii );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SELECT_LAYER_DIALOG::OnCancelClick( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
EndModal( -1 );
|
|
|
|
}
|
|
|
|
|
2013-03-31 13:27:46 +00:00
|
|
|
const wxString GetPCBDefaultLayerName( LAYER_NUM aLayerNumber )
|
2012-05-04 17:44:42 +00:00
|
|
|
{
|
|
|
|
const wxChar* txt;
|
|
|
|
|
|
|
|
// Use a switch to explicitly show the mapping more clearly
|
|
|
|
switch( aLayerNumber )
|
|
|
|
{
|
2013-04-10 07:03:19 +00:00
|
|
|
case LAYER_N_FRONT: txt = wxT( "F.Cu" ); break;
|
|
|
|
case LAYER_N_2: txt = wxT( "Inner1.Cu" ); break;
|
|
|
|
case LAYER_N_3: txt = wxT( "Inner2.Cu" ); break;
|
|
|
|
case LAYER_N_4: txt = wxT( "Inner3.Cu" ); break;
|
|
|
|
case LAYER_N_5: txt = wxT( "Inner4.Cu" ); break;
|
|
|
|
case LAYER_N_6: txt = wxT( "Inner5.Cu" ); break;
|
|
|
|
case LAYER_N_7: txt = wxT( "Inner6.Cu" ); break;
|
|
|
|
case LAYER_N_8: txt = wxT( "Inner7.Cu" ); break;
|
|
|
|
case LAYER_N_9: txt = wxT( "Inner8.Cu" ); break;
|
|
|
|
case LAYER_N_10: txt = wxT( "Inner9.Cu" ); break;
|
|
|
|
case LAYER_N_11: txt = wxT( "Inner10.Cu" ); break;
|
|
|
|
case LAYER_N_12: txt = wxT( "Inner11.Cu" ); break;
|
|
|
|
case LAYER_N_13: txt = wxT( "Inner12.Cu" ); break;
|
|
|
|
case LAYER_N_14: txt = wxT( "Inner13.Cu" ); break;
|
|
|
|
case LAYER_N_15: txt = wxT( "Inner14.Cu" ); break;
|
|
|
|
case LAYER_N_BACK: txt = wxT( "B.Cu" ); break;
|
|
|
|
case ADHESIVE_N_BACK: txt = wxT( "B.Adhes" ); break;
|
|
|
|
case ADHESIVE_N_FRONT: txt = wxT( "F.Adhes" ); break;
|
|
|
|
case SOLDERPASTE_N_BACK: txt = wxT( "B.Paste" ); break;
|
|
|
|
case SOLDERPASTE_N_FRONT: txt = wxT( "F.Paste" ); break;
|
|
|
|
case SILKSCREEN_N_BACK: txt = wxT( "B.SilkS" ); break;
|
|
|
|
case SILKSCREEN_N_FRONT: txt = wxT( "F.SilkS" ); break;
|
|
|
|
case SOLDERMASK_N_BACK: txt = wxT( "B.Mask" ); break;
|
|
|
|
case SOLDERMASK_N_FRONT: txt = wxT( "F.Mask" ); break;
|
|
|
|
case DRAW_N: txt = wxT( "Dwgs.User" ); break;
|
|
|
|
case COMMENT_N: txt = wxT( "Cmts.User" ); break;
|
|
|
|
case ECO1_N: txt = wxT( "Eco1.User" ); break;
|
|
|
|
case ECO2_N: txt = wxT( "Eco2.User" ); break;
|
|
|
|
case EDGE_N: txt = wxT( "Edge.Cuts" ); break;
|
|
|
|
default: txt = wxT( "BAD_INDEX" ); break;
|
2012-05-04 17:44:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return wxString( txt );
|
|
|
|
}
|