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>
|
|
|
|
|
2014-07-14 18:59:41 +00:00
|
|
|
#define NB_PCB_LAYERS LAYER_ID_COUNT
|
|
|
|
#define FIRST_COPPER_LAYER 0
|
|
|
|
#define LAST_COPPER_LAYER 31
|
|
|
|
|
2012-05-04 17:44:42 +00:00
|
|
|
// Exported function
|
2014-07-14 18:59:41 +00:00
|
|
|
const wxString GetPCBDefaultLayerName( int aLayerId );
|
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:
|
2014-07-14 18:59:41 +00:00
|
|
|
wxRadioBox* m_layerList;
|
|
|
|
std::vector <int> m_layerId;
|
2012-05-04 17:44:42 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
// Constructor and destructor
|
2014-06-27 17:07:42 +00:00
|
|
|
SELECT_LAYER_DIALOG( GERBVIEW_FRAME* parent, int 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
|
2014-06-27 17:07:42 +00:00
|
|
|
* @param aDefaultLayer = Preselection (GERBER_DRAWLAYERS_COUNT for "(Deselect)" layer)
|
2012-05-04 17:44:42 +00:00
|
|
|
* @param aCopperLayerCount = number of copper layers
|
|
|
|
* @param aShowDeselectOption = display a "(Deselect)" radiobutton (when set to true)
|
2014-06-27 17:07:42 +00:00
|
|
|
* @return new layer value (GERBER_DRAWLAYERS_COUNT when "(Deselect)" radiobutton selected),
|
2012-05-04 17:44:42 +00:00
|
|
|
* 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).
|
|
|
|
*/
|
2014-06-27 17:07:42 +00:00
|
|
|
int GERBVIEW_FRAME::SelectPCBLayer( int aDefaultLayer, int aCopperLayerCount,
|
2013-04-10 07:03:19 +00:00
|
|
|
bool aShowDeselectOption )
|
2012-05-04 17:44:42 +00:00
|
|
|
{
|
|
|
|
SELECT_LAYER_DIALOG* frame = new SELECT_LAYER_DIALOG( this, aDefaultLayer,
|
|
|
|
aCopperLayerCount,
|
|
|
|
aShowDeselectOption );
|
|
|
|
|
2014-07-14 18:59:41 +00:00
|
|
|
int layer = frame->ShowModal();
|
2012-05-04 17:44:42 +00:00
|
|
|
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,
|
2014-06-27 17:07:42 +00:00
|
|
|
int 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
|
|
|
{
|
2014-07-14 18:59:41 +00:00
|
|
|
wxButton* button;
|
2014-06-27 17:07:42 +00:00
|
|
|
int ii;
|
2014-07-14 18:59:41 +00:00
|
|
|
wxArrayString layerList;
|
|
|
|
int layerSelect = -1;
|
2012-05-04 17:44:42 +00:00
|
|
|
|
|
|
|
// Build the layer list; first build copper layers list
|
2014-07-14 18:59:41 +00:00
|
|
|
int layerCount = 0;
|
2014-06-27 17:07:42 +00:00
|
|
|
|
|
|
|
for( ii = FIRST_COPPER_LAYER; ii <= LAST_COPPER_LAYER; ++ii )
|
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
|
|
|
{
|
2014-07-14 18:59:41 +00:00
|
|
|
layerList.Add( GetPCBDefaultLayerName( ii ) );
|
2012-05-04 17:44:42 +00:00
|
|
|
|
|
|
|
if( ii == aDefaultLayer )
|
2014-07-14 18:59:41 +00:00
|
|
|
layerSelect = layerCount;
|
2012-05-04 17:44:42 +00:00
|
|
|
|
2014-07-14 18:59:41 +00:00
|
|
|
m_layerId.push_back( ii );
|
|
|
|
layerCount++;
|
2012-05-04 17:44:42 +00:00
|
|
|
}
|
|
|
|
}
|
2014-06-27 17:07:42 +00:00
|
|
|
|
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
|
|
|
{
|
2014-07-14 18:59:41 +00:00
|
|
|
layerList.Add( GetPCBDefaultLayerName( ii ) );
|
2012-05-04 17:44:42 +00:00
|
|
|
|
|
|
|
if( ii == aDefaultLayer )
|
2014-07-14 18:59:41 +00:00
|
|
|
layerSelect = layerCount;
|
2012-05-04 17:44:42 +00:00
|
|
|
|
2014-07-14 18:59:41 +00:00
|
|
|
m_layerId.push_back( ii );
|
|
|
|
layerCount++;
|
2012-05-04 17:44:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// When appropriate, also provide a "(Deselect)" radiobutton
|
|
|
|
if( aShowDeselectOption )
|
|
|
|
{
|
2014-07-14 18:59:41 +00:00
|
|
|
layerList.Add( _( "Do not export" ) );
|
2012-05-04 17:44:42 +00:00
|
|
|
|
2014-07-14 18:59:41 +00:00
|
|
|
if( UNSELECTED_LAYER == aDefaultLayer )
|
|
|
|
layerSelect = layerCount;
|
2012-05-04 17:44:42 +00:00
|
|
|
|
2014-07-14 18:59:41 +00:00
|
|
|
m_layerId.push_back( UNSELECTED_LAYER );
|
|
|
|
layerCount++;
|
2012-05-04 17:44:42 +00:00
|
|
|
}
|
|
|
|
|
2014-07-14 18:59:41 +00:00
|
|
|
m_layerList = new wxRadioBox( this, ID_LAYER_SELECT, _( "Layer" ),
|
2012-05-04 17:44:42 +00:00
|
|
|
wxPoint( -1, -1 ), wxSize( -1, -1 ),
|
2014-07-14 18:59:41 +00:00
|
|
|
layerList,
|
|
|
|
(layerCount < 8) ? layerCount : 8,
|
2012-05-04 17:44:42 +00:00
|
|
|
wxRA_SPECIFY_ROWS );
|
|
|
|
|
2014-07-14 18:59:41 +00:00
|
|
|
if( layerSelect >= 0 )
|
|
|
|
m_layerList->SetSelection( layerSelect );
|
2012-05-04 17:44:42 +00:00
|
|
|
|
|
|
|
wxBoxSizer* FrameBoxSizer = new wxBoxSizer( wxHORIZONTAL );
|
|
|
|
SetSizer( FrameBoxSizer );
|
2014-07-14 18:59:41 +00:00
|
|
|
FrameBoxSizer->Add( m_layerList, 0, wxALIGN_TOP | wxALL, 5 );
|
2012-05-04 17:44:42 +00:00
|
|
|
wxBoxSizer* ButtonBoxSizer = new wxBoxSizer( wxVERTICAL );
|
|
|
|
FrameBoxSizer->Add( ButtonBoxSizer, 0, wxALIGN_BOTTOM | wxALL, 0 );
|
|
|
|
|
2014-07-14 18:59:41 +00:00
|
|
|
button = new wxButton( this, wxID_OK, _( "OK" ) );
|
|
|
|
button->SetDefault();
|
|
|
|
ButtonBoxSizer->Add( button, 0, wxGROW | wxALL, 5 );
|
2012-05-04 17:44:42 +00:00
|
|
|
|
2014-07-14 18:59:41 +00:00
|
|
|
button = new wxButton( this, wxID_CANCEL, _( "Cancel" ) );
|
|
|
|
ButtonBoxSizer->Add( button, 0, wxGROW | wxALL, 5 );
|
2012-05-04 17:44:42 +00:00
|
|
|
|
|
|
|
GetSizer()->SetSizeHints( this );
|
|
|
|
|
|
|
|
Center();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SELECT_LAYER_DIALOG::OnLayerSelected( wxCommandEvent& event )
|
|
|
|
{
|
2014-07-14 18:59:41 +00:00
|
|
|
int ii = m_layerId[m_layerList->GetSelection()];
|
2012-05-04 17:44:42 +00:00
|
|
|
|
|
|
|
EndModal( ii );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SELECT_LAYER_DIALOG::OnCancelClick( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
EndModal( -1 );
|
|
|
|
}
|
|
|
|
|
2014-07-14 18:59:41 +00:00
|
|
|
// This function is a duplicate of
|
|
|
|
// const wxChar* LSET::Name( LAYER_ID aLayerId )
|
|
|
|
// However it avoids a dependency to Pcbnew code.
|
|
|
|
const wxString GetPCBDefaultLayerName( int aLayerId )
|
2012-05-04 17:44:42 +00:00
|
|
|
{
|
|
|
|
const wxChar* txt;
|
|
|
|
|
2014-07-14 18:59:41 +00:00
|
|
|
// using a switch to explicitly show the mapping more clearly
|
|
|
|
switch( aLayerId )
|
2012-05-04 17:44:42 +00:00
|
|
|
{
|
2014-07-14 18:59:41 +00:00
|
|
|
case F_Cu: txt = wxT( "F.Cu" ); break;
|
|
|
|
case In1_Cu: txt = wxT( "In1.Cu" ); break;
|
|
|
|
case In2_Cu: txt = wxT( "In2.Cu" ); break;
|
|
|
|
case In3_Cu: txt = wxT( "In3.Cu" ); break;
|
|
|
|
case In4_Cu: txt = wxT( "In4.Cu" ); break;
|
|
|
|
case In5_Cu: txt = wxT( "In5.Cu" ); break;
|
|
|
|
case In6_Cu: txt = wxT( "In6.Cu" ); break;
|
|
|
|
case In7_Cu: txt = wxT( "In7.Cu" ); break;
|
|
|
|
case In8_Cu: txt = wxT( "In8.Cu" ); break;
|
|
|
|
case In9_Cu: txt = wxT( "In9.Cu" ); break;
|
|
|
|
case In10_Cu: txt = wxT( "In10.Cu" ); break;
|
|
|
|
case In11_Cu: txt = wxT( "In11.Cu" ); break;
|
|
|
|
case In12_Cu: txt = wxT( "In12.Cu" ); break;
|
|
|
|
case In13_Cu: txt = wxT( "In13.Cu" ); break;
|
|
|
|
case In14_Cu: txt = wxT( "In14.Cu" ); break;
|
|
|
|
case In15_Cu: txt = wxT( "In15.Cu" ); break;
|
|
|
|
case In16_Cu: txt = wxT( "In16.Cu" ); break;
|
|
|
|
case In17_Cu: txt = wxT( "In17.Cu" ); break;
|
|
|
|
case In18_Cu: txt = wxT( "In18.Cu" ); break;
|
|
|
|
case In19_Cu: txt = wxT( "In19.Cu" ); break;
|
|
|
|
case In20_Cu: txt = wxT( "In20.Cu" ); break;
|
|
|
|
case In21_Cu: txt = wxT( "In21.Cu" ); break;
|
|
|
|
case In22_Cu: txt = wxT( "In22.Cu" ); break;
|
|
|
|
case In23_Cu: txt = wxT( "In23.Cu" ); break;
|
|
|
|
case In24_Cu: txt = wxT( "In24.Cu" ); break;
|
|
|
|
case In25_Cu: txt = wxT( "In25.Cu" ); break;
|
|
|
|
case In26_Cu: txt = wxT( "In26.Cu" ); break;
|
|
|
|
case In27_Cu: txt = wxT( "In27.Cu" ); break;
|
|
|
|
case In28_Cu: txt = wxT( "In28.Cu" ); break;
|
|
|
|
case In29_Cu: txt = wxT( "In29.Cu" ); break;
|
|
|
|
case In30_Cu: txt = wxT( "In30.Cu" ); break;
|
|
|
|
case B_Cu: txt = wxT( "B.Cu" ); break;
|
|
|
|
|
|
|
|
// Technicals
|
|
|
|
case B_Adhes: txt = wxT( "B.Adhes" ); break;
|
|
|
|
case F_Adhes: txt = wxT( "F.Adhes" ); break;
|
|
|
|
case B_Paste: txt = wxT( "B.Paste" ); break;
|
|
|
|
case F_Paste: txt = wxT( "F.Paste" ); break;
|
|
|
|
case B_SilkS: txt = wxT( "B.SilkS" ); break;
|
|
|
|
case F_SilkS: txt = wxT( "F.SilkS" ); break;
|
|
|
|
case B_Mask: txt = wxT( "B.Mask" ); break;
|
|
|
|
case F_Mask: txt = wxT( "F.Mask" ); break;
|
|
|
|
|
|
|
|
// Users
|
|
|
|
case Dwgs_User: txt = wxT( "Dwgs.User" ); break;
|
|
|
|
case Cmts_User: txt = wxT( "Cmts.User" ); break;
|
|
|
|
case Eco1_User: txt = wxT( "Eco1.User" ); break;
|
|
|
|
case Eco2_User: txt = wxT( "Eco2.User" ); break;
|
|
|
|
case Edge_Cuts: txt = wxT( "Edge.Cuts" ); break;
|
|
|
|
case Margin: txt = wxT( "Margin" ); break;
|
|
|
|
|
|
|
|
// Footprint
|
|
|
|
case F_CrtYd: txt = wxT( "F.CrtYd" ); break;
|
|
|
|
case B_CrtYd: txt = wxT( "B.CrtYd" ); break;
|
|
|
|
case F_Fab: txt = wxT( "F.Fab" ); break;
|
|
|
|
case B_Fab: txt = wxT( "B.Fab" ); break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
wxASSERT_MSG( 0, wxT( "aLayerId out of range" ) );
|
|
|
|
txt = wxT( "BAD INDEX!" ); break;
|
2012-05-04 17:44:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return wxString( txt );
|
|
|
|
}
|