KiCad PCB EDA Suite
dialog_select_one_pcb_layer.cpp
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2012-2014 Jean-Pierre Charras jp.charras at wanadoo.fr
5  * Copyright (C) 1992-2014 KiCad Developers, see change_log.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
30 #include <fctsys.h>
31 #include <gerbview_frame.h>
32 #include <select_layers_to_pcb.h>
33 
34 #define NB_PCB_LAYERS LAYER_ID_COUNT
35 #define FIRST_COPPER_LAYER 0
36 #define LAST_COPPER_LAYER 31
37 
38 // Exported function
39 const wxString GetPCBDefaultLayerName( int aLayerId );
40 
41 
46 };
47 
48 
49 class SELECT_LAYER_DIALOG : public wxDialog
50 {
51 private:
52  wxRadioBox* m_layerList;
53  std::vector <int> m_layerId;
54 
55 public:
56  // Constructor and destructor
57  SELECT_LAYER_DIALOG( GERBVIEW_FRAME* parent, int aDefaultLayer,
58  int aCopperLayerCount, bool aShowDeselectOption );
60 
61 private:
62  void OnLayerSelected( wxCommandEvent& event );
63  void OnCancelClick( wxCommandEvent& event );
64 
65  DECLARE_EVENT_TABLE()
66 };
67 
68 
69 BEGIN_EVENT_TABLE( SELECT_LAYER_DIALOG, wxDialog )
70  EVT_BUTTON( wxID_OK, SELECT_LAYER_DIALOG::OnLayerSelected )
71  EVT_BUTTON( wxID_CANCEL, SELECT_LAYER_DIALOG::OnCancelClick )
72  EVT_RADIOBOX( ID_LAYER_SELECT, SELECT_LAYER_DIALOG::OnLayerSelected )
73 END_EVENT_TABLE()
74 
75 
91 int GERBVIEW_FRAME::SelectPCBLayer( int aDefaultLayer, int aCopperLayerCount,
92  bool aShowDeselectOption )
93 {
94  SELECT_LAYER_DIALOG* frame = new SELECT_LAYER_DIALOG( this, aDefaultLayer,
95  aCopperLayerCount,
96  aShowDeselectOption );
97 
98  int layer = frame->ShowModal();
99  frame->Destroy();
100  return layer;
101 }
102 
103 
104 /*
105  * The "OK" and "Cancel" buttons are positioned (in a horizontal line)
106  * beneath the "Layer" radiobox, unless that contains only one column of
107  * radiobuttons, in which case they are positioned (in a vertical line)
108  * to the right of that radiobox.
109  */
111  int aDefaultLayer, int aCopperLayerCount,
112  bool aShowDeselectOption ) :
113  wxDialog( parent, -1, _( "Select Layer:" ), wxPoint( -1, -1 ),
114  wxSize( 470, 250 ),
115  wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER )
116 {
117  wxButton* button;
118  int ii;
119  wxArrayString layerList;
120  int layerSelect = -1;
121 
122  // Build the layer list; first build copper layers list
123  int layerCount = 0;
124 
125  for( ii = FIRST_COPPER_LAYER; ii <= LAST_COPPER_LAYER; ++ii )
126  {
127  if( ii == FIRST_COPPER_LAYER || ii == LAST_COPPER_LAYER || ii < aCopperLayerCount-1 )
128  {
129  layerList.Add( GetPCBDefaultLayerName( ii ) );
130 
131  if( ii == aDefaultLayer )
132  layerSelect = layerCount;
133 
134  m_layerId.push_back( ii );
135  layerCount++;
136  }
137  }
138 
139  // Build the layer list; build non copper layers list
140  for( ; ii < NB_PCB_LAYERS; ++ii )
141  {
142  layerList.Add( GetPCBDefaultLayerName( ii ) );
143 
144  if( ii == aDefaultLayer )
145  layerSelect = layerCount;
146 
147  m_layerId.push_back( ii );
148  layerCount++;
149  }
150 
151  // When appropriate, also provide a "(Deselect)" radiobutton
152  if( aShowDeselectOption )
153  {
154  layerList.Add( _( "Do not export" ) );
155 
156  if( UNSELECTED_LAYER == aDefaultLayer )
157  layerSelect = layerCount;
158 
159  m_layerId.push_back( UNSELECTED_LAYER );
160  layerCount++;
161  }
162 
163  m_layerList = new wxRadioBox( this, ID_LAYER_SELECT, _( "Layer" ),
164  wxPoint( -1, -1 ), wxSize( -1, -1 ),
165  layerList,
166  (layerCount < 8) ? layerCount : 8,
167  wxRA_SPECIFY_ROWS );
168 
169  if( layerSelect >= 0 )
170  m_layerList->SetSelection( layerSelect );
171 
172  wxBoxSizer* FrameBoxSizer = new wxBoxSizer( wxHORIZONTAL );
173  SetSizer( FrameBoxSizer );
174  FrameBoxSizer->Add( m_layerList, 0, wxALIGN_TOP | wxALL, 5 );
175  wxBoxSizer* ButtonBoxSizer = new wxBoxSizer( wxVERTICAL );
176  FrameBoxSizer->Add( ButtonBoxSizer, 0, wxALIGN_BOTTOM | wxALL, 0 );
177 
178  button = new wxButton( this, wxID_OK, _( "OK" ) );
179  button->SetDefault();
180  ButtonBoxSizer->Add( button, 0, wxGROW | wxALL, 5 );
181 
182  button = new wxButton( this, wxID_CANCEL, _( "Cancel" ) );
183  ButtonBoxSizer->Add( button, 0, wxGROW | wxALL, 5 );
184 
185  GetSizer()->SetSizeHints( this );
186 
187  Center();
188 }
189 
190 
191 void SELECT_LAYER_DIALOG::OnLayerSelected( wxCommandEvent& event )
192 {
193  int ii = m_layerId[m_layerList->GetSelection()];
194 
195  EndModal( ii );
196 }
197 
198 
199 void SELECT_LAYER_DIALOG::OnCancelClick( wxCommandEvent& event )
200 {
201  EndModal( -1 );
202 }
203 
204 // This function is a duplicate of
205 // const wxChar* LSET::Name( LAYER_ID aLayerId )
206 // However it avoids a dependency to Pcbnew code.
207 const wxString GetPCBDefaultLayerName( int aLayerId )
208 {
209  const wxChar* txt;
210 
211  // using a switch to explicitly show the mapping more clearly
212  switch( aLayerId )
213  {
214  case F_Cu: txt = wxT( "F.Cu" ); break;
215  case In1_Cu: txt = wxT( "In1.Cu" ); break;
216  case In2_Cu: txt = wxT( "In2.Cu" ); break;
217  case In3_Cu: txt = wxT( "In3.Cu" ); break;
218  case In4_Cu: txt = wxT( "In4.Cu" ); break;
219  case In5_Cu: txt = wxT( "In5.Cu" ); break;
220  case In6_Cu: txt = wxT( "In6.Cu" ); break;
221  case In7_Cu: txt = wxT( "In7.Cu" ); break;
222  case In8_Cu: txt = wxT( "In8.Cu" ); break;
223  case In9_Cu: txt = wxT( "In9.Cu" ); break;
224  case In10_Cu: txt = wxT( "In10.Cu" ); break;
225  case In11_Cu: txt = wxT( "In11.Cu" ); break;
226  case In12_Cu: txt = wxT( "In12.Cu" ); break;
227  case In13_Cu: txt = wxT( "In13.Cu" ); break;
228  case In14_Cu: txt = wxT( "In14.Cu" ); break;
229  case In15_Cu: txt = wxT( "In15.Cu" ); break;
230  case In16_Cu: txt = wxT( "In16.Cu" ); break;
231  case In17_Cu: txt = wxT( "In17.Cu" ); break;
232  case In18_Cu: txt = wxT( "In18.Cu" ); break;
233  case In19_Cu: txt = wxT( "In19.Cu" ); break;
234  case In20_Cu: txt = wxT( "In20.Cu" ); break;
235  case In21_Cu: txt = wxT( "In21.Cu" ); break;
236  case In22_Cu: txt = wxT( "In22.Cu" ); break;
237  case In23_Cu: txt = wxT( "In23.Cu" ); break;
238  case In24_Cu: txt = wxT( "In24.Cu" ); break;
239  case In25_Cu: txt = wxT( "In25.Cu" ); break;
240  case In26_Cu: txt = wxT( "In26.Cu" ); break;
241  case In27_Cu: txt = wxT( "In27.Cu" ); break;
242  case In28_Cu: txt = wxT( "In28.Cu" ); break;
243  case In29_Cu: txt = wxT( "In29.Cu" ); break;
244  case In30_Cu: txt = wxT( "In30.Cu" ); break;
245  case B_Cu: txt = wxT( "B.Cu" ); break;
246 
247  // Technicals
248  case B_Adhes: txt = wxT( "B.Adhes" ); break;
249  case F_Adhes: txt = wxT( "F.Adhes" ); break;
250  case B_Paste: txt = wxT( "B.Paste" ); break;
251  case F_Paste: txt = wxT( "F.Paste" ); break;
252  case B_SilkS: txt = wxT( "B.SilkS" ); break;
253  case F_SilkS: txt = wxT( "F.SilkS" ); break;
254  case B_Mask: txt = wxT( "B.Mask" ); break;
255  case F_Mask: txt = wxT( "F.Mask" ); break;
256 
257  // Users
258  case Dwgs_User: txt = wxT( "Dwgs.User" ); break;
259  case Cmts_User: txt = wxT( "Cmts.User" ); break;
260  case Eco1_User: txt = wxT( "Eco1.User" ); break;
261  case Eco2_User: txt = wxT( "Eco2.User" ); break;
262  case Edge_Cuts: txt = wxT( "Edge.Cuts" ); break;
263  case Margin: txt = wxT( "Margin" ); break;
264 
265  // Footprint
266  case F_CrtYd: txt = wxT( "F.CrtYd" ); break;
267  case B_CrtYd: txt = wxT( "B.CrtYd" ); break;
268  case F_Fab: txt = wxT( "F.Fab" ); break;
269  case B_Fab: txt = wxT( "B.Fab" ); break;
270 
271  default:
272  wxASSERT_MSG( 0, wxT( "aLayerId out of range" ) );
273  txt = wxT( "BAD INDEX!" ); break;
274  }
275 
276  return wxString( txt );
277 }
const wxString GetPCBDefaultLayerName(int aLayerId)
#define NB_PCB_LAYERS
void OnCancelClick(wxCommandEvent &event)
void OnLayerSelected(wxCommandEvent &event)
SELECT_LAYER_DIALOG(GERBVIEW_FRAME *parent, int aDefaultLayer, int aCopperLayerCount, bool aShowDeselectOption)
#define FIRST_COPPER_LAYER
#define LAST_COPPER_LAYER