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 PCB_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 )
73 END_EVENT_TABLE()
74 
75 
76 
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 )
141  {
142  if( GetPCBDefaultLayerName( ii ) == "" ) // End of list
143  break;
144 
145  layerList.Add( GetPCBDefaultLayerName( ii ) );
146 
147  if( ii == aDefaultLayer )
148  layerSelect = layerCount;
149 
150  m_layerId.push_back( ii );
151  layerCount++;
152  }
153 
154  // When appropriate, also provide a "(Deselect)" radiobutton
155  if( aShowDeselectOption )
156  {
157  layerList.Add( _( "Do not export" ) );
158 
159  if( UNSELECTED_LAYER == aDefaultLayer )
160  layerSelect = layerCount;
161 
162  m_layerId.push_back( UNSELECTED_LAYER );
163  layerCount++;
164  }
165 
166  m_layerList = new wxRadioBox( this, ID_LAYER_SELECT, _( "Layer" ),
167  wxPoint( -1, -1 ), wxSize( -1, -1 ),
168  layerList,
169  (layerCount < 8) ? layerCount : 8,
170  wxRA_SPECIFY_ROWS );
171 
172  if( layerSelect >= 0 )
173  m_layerList->SetSelection( layerSelect );
174 
175  wxBoxSizer* FrameBoxSizer = new wxBoxSizer( wxHORIZONTAL );
176  SetSizer( FrameBoxSizer );
177  FrameBoxSizer->Add( m_layerList, 0, wxALIGN_TOP | wxALL, 5 );
178  wxBoxSizer* ButtonBoxSizer = new wxBoxSizer( wxVERTICAL );
179  FrameBoxSizer->Add( ButtonBoxSizer, 0, wxALIGN_BOTTOM | wxALL, 0 );
180 
181  button = new wxButton( this, wxID_OK, _( "OK" ) );
182  button->SetDefault();
183  ButtonBoxSizer->Add( button, 0, wxGROW | wxALL, 5 );
184 
185  button = new wxButton( this, wxID_CANCEL, _( "Cancel" ) );
186  ButtonBoxSizer->Add( button, 0, wxGROW | wxALL, 5 );
187 
188  GetSizer()->SetSizeHints( this );
189 
190  Center();
191 }
192 
193 
194 void SELECT_LAYER_DIALOG::OnLayerSelected( wxCommandEvent& event )
195 {
196  int ii = m_layerId[m_layerList->GetSelection()];
197 
198  EndModal( ii );
199 }
200 
201 
202 void SELECT_LAYER_DIALOG::OnCancelClick( wxCommandEvent& event )
203 {
204  EndModal( -1 );
205 }
206 
207 // This function is a duplicate of
208 // const wxChar* LSET::Name( PCB_LAYER_ID aLayerId )
209 // However it avoids a dependency to Pcbnew code.
210 const wxString GetPCBDefaultLayerName( int aLayerId )
211 {
212  const wxChar* txt;
213 
214  // using a switch to explicitly show the mapping more clearly
215  switch( aLayerId )
216  {
217  case F_Cu: txt = wxT( "F.Cu" ); break;
218  case In1_Cu: txt = wxT( "In1.Cu" ); break;
219  case In2_Cu: txt = wxT( "In2.Cu" ); break;
220  case In3_Cu: txt = wxT( "In3.Cu" ); break;
221  case In4_Cu: txt = wxT( "In4.Cu" ); break;
222  case In5_Cu: txt = wxT( "In5.Cu" ); break;
223  case In6_Cu: txt = wxT( "In6.Cu" ); break;
224  case In7_Cu: txt = wxT( "In7.Cu" ); break;
225  case In8_Cu: txt = wxT( "In8.Cu" ); break;
226  case In9_Cu: txt = wxT( "In9.Cu" ); break;
227  case In10_Cu: txt = wxT( "In10.Cu" ); break;
228  case In11_Cu: txt = wxT( "In11.Cu" ); break;
229  case In12_Cu: txt = wxT( "In12.Cu" ); break;
230  case In13_Cu: txt = wxT( "In13.Cu" ); break;
231  case In14_Cu: txt = wxT( "In14.Cu" ); break;
232  case In15_Cu: txt = wxT( "In15.Cu" ); break;
233  case In16_Cu: txt = wxT( "In16.Cu" ); break;
234  case In17_Cu: txt = wxT( "In17.Cu" ); break;
235  case In18_Cu: txt = wxT( "In18.Cu" ); break;
236  case In19_Cu: txt = wxT( "In19.Cu" ); break;
237  case In20_Cu: txt = wxT( "In20.Cu" ); break;
238  case In21_Cu: txt = wxT( "In21.Cu" ); break;
239  case In22_Cu: txt = wxT( "In22.Cu" ); break;
240  case In23_Cu: txt = wxT( "In23.Cu" ); break;
241  case In24_Cu: txt = wxT( "In24.Cu" ); break;
242  case In25_Cu: txt = wxT( "In25.Cu" ); break;
243  case In26_Cu: txt = wxT( "In26.Cu" ); break;
244  case In27_Cu: txt = wxT( "In27.Cu" ); break;
245  case In28_Cu: txt = wxT( "In28.Cu" ); break;
246  case In29_Cu: txt = wxT( "In29.Cu" ); break;
247  case In30_Cu: txt = wxT( "In30.Cu" ); break;
248  case B_Cu: txt = wxT( "B.Cu" ); break;
249 
250  // Technicals
251  case B_Adhes: txt = wxT( "B.Adhes" ); break;
252  case F_Adhes: txt = wxT( "F.Adhes" ); break;
253  case B_Paste: txt = wxT( "B.Paste" ); break;
254  case F_Paste: txt = wxT( "F.Paste" ); break;
255  case B_SilkS: txt = wxT( "B.SilkS" ); break;
256  case F_SilkS: txt = wxT( "F.SilkS" ); break;
257  case B_Mask: txt = wxT( "B.Mask" ); break;
258  case F_Mask: txt = wxT( "F.Mask" ); break;
259 
260  // Users
261  case Dwgs_User: txt = wxT( "Dwgs.User" ); break;
262  case Cmts_User: txt = wxT( "Cmts.User" ); break;
263  case Eco1_User: txt = wxT( "Eco1.User" ); break;
264  case Eco2_User: txt = wxT( "Eco2.User" ); break;
265  case Edge_Cuts: txt = wxT( "Edge.Cuts" ); break;
266 
267  // Pcbnew konws some oter layers. But any other layer is not suitable for export.
268 
269  default: // Sentinel
270  txt = wxT( "" ); break;
271  }
272 
273  return wxString( txt );
274 }
const wxString GetPCBDefaultLayerName(int aLayerId)
void OnCancelClick(wxCommandEvent &event)
#define _(s)
void OnLayerSelected(wxCommandEvent &event)
SELECT_LAYER_DIALOG(GERBVIEW_FRAME *parent, int aDefaultLayer, int aCopperLayerCount, bool aShowDeselectOption)
#define FIRST_COPPER_LAYER
#define LAST_COPPER_LAYER