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-2020 KiCad Developers, see AUTHORS.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 <gerbview_frame.h>
32 
33 #include <wx/radiobox.h>
34 
35 #define NB_PCB_LAYERS PCB_LAYER_ID_COUNT
36 #define FIRST_COPPER_LAYER 0
37 #define LAST_COPPER_LAYER 31
38 
39 // Exported function
40 const wxString GetPCBDefaultLayerName( int aLayerId );
41 
42 
47 };
48 
49 
51 {
52 private:
53  int m_PassedDefaultLayer; // Remember this in case user hits Cancel
54  wxRadioBox* m_layerRadioBox;
55  std::vector <int> m_layerId;
56 
57 public:
58  // Constructor and destructor
59  SELECT_LAYER_DIALOG( GERBVIEW_FRAME* parent, int aDefaultLayer, int aCopperLayerCount,
60  wxString aGerberName );
62 
63 private:
64  void OnLayerSelected( wxCommandEvent& event );
65  void OnCancelClick( wxCommandEvent& event );
66 
68 };
69 
70 
71 BEGIN_EVENT_TABLE( SELECT_LAYER_DIALOG, wxDialog )
72  EVT_BUTTON( wxID_OK, SELECT_LAYER_DIALOG::OnLayerSelected )
73  EVT_BUTTON( wxID_CANCEL, SELECT_LAYER_DIALOG::OnCancelClick )
75 END_EVENT_TABLE()
76 
77 
78 
93 int GERBVIEW_FRAME::SelectPCBLayer( int aDefaultLayer, int aCopperLayerCount, wxString aGerberName )
94 {
95  SELECT_LAYER_DIALOG* frame =
96  new SELECT_LAYER_DIALOG( this, aDefaultLayer, aCopperLayerCount, aGerberName );
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  GERBVIEW_FRAME* parent, int aDefaultLayer, int aCopperLayerCount, wxString aGerberName )
112  : DIALOG_SHIM( parent, -1, wxString::Format( _( "Select Layer: %s" ), aGerberName ),
113  wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER )
114 {
115  wxButton* button;
116  int ii;
117  wxArrayString layerList;
118  int selected = -1;
119 
120  // Store the passed default layer in case the user hits Cancel
121  m_PassedDefaultLayer = aDefaultLayer;
122 
123  // Build the layer list; first build copper layers list
124  int layerCount = 0;
125 
126  for( ii = FIRST_COPPER_LAYER; ii <= LAST_COPPER_LAYER; ++ii )
127  {
128  if( ii == FIRST_COPPER_LAYER || ii == LAST_COPPER_LAYER || ii < aCopperLayerCount-1 )
129  {
130  layerList.Add( GetPCBDefaultLayerName( ii ) );
131 
132  if( aDefaultLayer == ii )
133  selected = layerCount;
134 
135  m_layerId.push_back( ii );
136  layerCount++;
137  }
138  }
139 
140  // Build the layer list; build non copper layers list
141  for( ; ; ++ii )
142  {
143  if( GetPCBDefaultLayerName( ii ) == "" ) // End of list
144  break;
145 
146  layerList.Add( GetPCBDefaultLayerName( ii ) );
147 
148  if( aDefaultLayer == ii )
149  selected = layerCount;
150 
151  m_layerId.push_back( ii );
152  layerCount++;
153  }
154 
155  layerList.Add( _( "Hole data" ) );
156 
157  if( aDefaultLayer == UNDEFINED_LAYER )
158  selected = layerCount;
159 
160  m_layerId.push_back( UNDEFINED_LAYER );
161  layerCount++;
162 
163  layerList.Add( _( "Do not export" ) );
164 
165  if( aDefaultLayer == UNSELECTED_LAYER )
166  selected = layerCount;
167 
168  m_layerId.push_back( UNSELECTED_LAYER );
169  layerCount++;
170 
171  m_layerRadioBox = new wxRadioBox( this, ID_LAYER_SELECT, _( "Layer" ), wxDefaultPosition,
172  wxDefaultSize, layerList, std::min( layerCount, 12 ),
173  wxRA_SPECIFY_ROWS );
174 
175  if( selected >= 0 )
176  m_layerRadioBox->SetSelection( selected );
177 
178  wxBoxSizer* mainSizer = new wxBoxSizer( wxHORIZONTAL );
179  SetSizer( mainSizer );
180  mainSizer->Add( m_layerRadioBox, 1, wxEXPAND | wxALIGN_TOP | wxALL, 5 );
181  wxBoxSizer* buttonsSizer = new wxBoxSizer( wxVERTICAL );
182  mainSizer->Add( buttonsSizer, 0, wxALIGN_BOTTOM | wxALL, 5 );
183 
184  button = new wxButton( this, wxID_OK, _( "OK" ) );
185  button->SetDefault();
186  buttonsSizer->Add( button, 0, wxGROW | wxALL, 5 );
187 
188  button = new wxButton( this, wxID_CANCEL, _( "Cancel" ) );
189  buttonsSizer->Add( button, 0, wxGROW | wxALL, 5 );
190 
191 #ifdef __WXOSX__
192  // Hack to fix clipped radio buttons on OSX
193  wxSize size = m_layerRadioBox->GetBestSize() + wxSize( 20, 0 );
194  m_layerRadioBox->SetMinSize( size );
195 #endif
196 
197  GetSizer()->SetSizeHints( this );
198 
199  Center();
200 }
201 
202 
203 void SELECT_LAYER_DIALOG::OnLayerSelected( wxCommandEvent& event )
204 {
205  int ii = m_layerId[m_layerRadioBox->GetSelection()];
206 
207  EndModal( ii );
208 }
209 
210 
211 void SELECT_LAYER_DIALOG::OnCancelClick( wxCommandEvent& event )
212 {
213  EndModal( m_PassedDefaultLayer );
214 }
215 
216 // This function is a duplicate of
217 // const wxChar* LSET::Name( PCB_LAYER_ID aLayerId )
218 // However it avoids a dependency to Pcbnew code.
219 const wxString GetPCBDefaultLayerName( int aLayerId )
220 {
221  const wxChar* txt;
222 
223  // using a switch to explicitly show the mapping more clearly
224  switch( aLayerId )
225  {
226  case F_Cu: txt = wxT( "F.Cu" ); break;
227  case In1_Cu: txt = wxT( "In1.Cu" ); break;
228  case In2_Cu: txt = wxT( "In2.Cu" ); break;
229  case In3_Cu: txt = wxT( "In3.Cu" ); break;
230  case In4_Cu: txt = wxT( "In4.Cu" ); break;
231  case In5_Cu: txt = wxT( "In5.Cu" ); break;
232  case In6_Cu: txt = wxT( "In6.Cu" ); break;
233  case In7_Cu: txt = wxT( "In7.Cu" ); break;
234  case In8_Cu: txt = wxT( "In8.Cu" ); break;
235  case In9_Cu: txt = wxT( "In9.Cu" ); break;
236  case In10_Cu: txt = wxT( "In10.Cu" ); break;
237  case In11_Cu: txt = wxT( "In11.Cu" ); break;
238  case In12_Cu: txt = wxT( "In12.Cu" ); break;
239  case In13_Cu: txt = wxT( "In13.Cu" ); break;
240  case In14_Cu: txt = wxT( "In14.Cu" ); break;
241  case In15_Cu: txt = wxT( "In15.Cu" ); break;
242  case In16_Cu: txt = wxT( "In16.Cu" ); break;
243  case In17_Cu: txt = wxT( "In17.Cu" ); break;
244  case In18_Cu: txt = wxT( "In18.Cu" ); break;
245  case In19_Cu: txt = wxT( "In19.Cu" ); break;
246  case In20_Cu: txt = wxT( "In20.Cu" ); break;
247  case In21_Cu: txt = wxT( "In21.Cu" ); break;
248  case In22_Cu: txt = wxT( "In22.Cu" ); break;
249  case In23_Cu: txt = wxT( "In23.Cu" ); break;
250  case In24_Cu: txt = wxT( "In24.Cu" ); break;
251  case In25_Cu: txt = wxT( "In25.Cu" ); break;
252  case In26_Cu: txt = wxT( "In26.Cu" ); break;
253  case In27_Cu: txt = wxT( "In27.Cu" ); break;
254  case In28_Cu: txt = wxT( "In28.Cu" ); break;
255  case In29_Cu: txt = wxT( "In29.Cu" ); break;
256  case In30_Cu: txt = wxT( "In30.Cu" ); break;
257  case B_Cu: txt = wxT( "B.Cu" ); break;
258 
259  // Technicals
260  case B_Adhes: txt = wxT( "B.Adhes" ); break;
261  case F_Adhes: txt = wxT( "F.Adhes" ); break;
262  case B_Paste: txt = wxT( "B.Paste" ); break;
263  case F_Paste: txt = wxT( "F.Paste" ); break;
264  case B_SilkS: txt = wxT( "B.SilkS" ); break;
265  case F_SilkS: txt = wxT( "F.SilkS" ); break;
266  case B_Mask: txt = wxT( "B.Mask" ); break;
267  case F_Mask: txt = wxT( "F.Mask" ); break;
268 
269  // Users
270  case Dwgs_User: txt = wxT( "Dwgs.User" ); break;
271  case Cmts_User: txt = wxT( "Cmts.User" ); break;
272  case Eco1_User: txt = wxT( "Eco1.User" ); break;
273  case Eco2_User: txt = wxT( "Eco2.User" ); break;
274  case Edge_Cuts: txt = wxT( "Edge.Cuts" ); break;
275 
276  // Pcbnew knows some other layers, but any other layer is not suitable for export.
277 
278  default: // Sentinel
279  txt = wxT( "" ); break;
280  }
281 
282  return wxString( txt );
283 }
const wxString GetPCBDefaultLayerName(int aLayerId)
Dialog helper object to sit in the inheritance tree between wxDialog and any class written by wxFormB...
Definition: dialog_shim.h:83
void OnCancelClick(wxCommandEvent &event)
void OnLayerSelected(wxCommandEvent &event)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
SELECT_LAYER_DIALOG(GERBVIEW_FRAME *parent, int aDefaultLayer, int aCopperLayerCount, wxString aGerberName)
#define _(s)
Definition: 3d_actions.cpp:33
#define FIRST_COPPER_LAYER
#define LAST_COPPER_LAYER