You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

281 lines
10 KiB

  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 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. /**
  25. * @file dialog_select_one_pcb_layer.cpp
  26. * @brief Set up a dialog to choose a PCB Layer.
  27. */
  28. #include <gerbview_frame.h>
  29. #include <dialogs/dialog_layers_select_to_pcb.h>
  30. #define NB_PCB_LAYERS PCB_LAYER_ID_COUNT
  31. #define FIRST_COPPER_LAYER 0
  32. #define LAST_COPPER_LAYER 31
  33. // Exported function
  34. const wxString GetPCBDefaultLayerName( int aLayerId );
  35. enum layer_sel_id {
  36. ID_LAYER_SELECT_TOP = 1800,
  37. ID_LAYER_SELECT_BOTTOM,
  38. ID_LAYER_SELECT
  39. };
  40. class SELECT_LAYER_DIALOG : public DIALOG_SHIM
  41. {
  42. private:
  43. int m_PassedDefaultLayer; // Remember this in case user hits Cancel
  44. wxRadioBox* m_layerRadioBox;
  45. std::vector <int> m_layerId;
  46. public:
  47. // Constructor and destructor
  48. SELECT_LAYER_DIALOG( GERBVIEW_FRAME* parent, int aDefaultLayer, int aCopperLayerCount,
  49. wxString aGerberName );
  50. ~SELECT_LAYER_DIALOG() { };
  51. private:
  52. void OnLayerSelected( wxCommandEvent& event );
  53. void OnCancelClick( wxCommandEvent& event );
  54. DECLARE_EVENT_TABLE()
  55. };
  56. BEGIN_EVENT_TABLE( SELECT_LAYER_DIALOG, wxDialog )
  57. EVT_BUTTON( wxID_OK, SELECT_LAYER_DIALOG::OnLayerSelected )
  58. EVT_BUTTON( wxID_CANCEL, SELECT_LAYER_DIALOG::OnCancelClick )
  59. EVT_RADIOBOX( ID_LAYER_SELECT, SELECT_LAYER_DIALOG::OnLayerSelected )
  60. END_EVENT_TABLE()
  61. /** Install the dialog box for layer selection
  62. * @param aDefaultLayer = Preselection (GERBER_DRAWLAYERS_COUNT for "(Deselect)" layer)
  63. * @param aCopperLayerCount = number of copper layers
  64. * @param aShowDeselectOption = display a "(Deselect)" radiobutton (when set to true)
  65. * @return new layer value (GERBER_DRAWLAYERS_COUNT when "(Deselect)" radiobutton selected),
  66. * or -1 if canceled
  67. *
  68. * Providing the option to also display a "(Deselect)" radiobutton makes the
  69. * GerbView's "Export to Pcbnew" command) more "user friendly",
  70. * by permitting any layer to be "deselected" immediately after its
  71. * corresponding radiobutton has been clicked on. (It would otherwise be
  72. * necessary to first cancel the "Select Layer:" dialog box (invoked after a
  73. * different radiobutton is clicked on) prior to then clicking on the "Deselect"
  74. * button provided within the "Layer selection:" dialog box).
  75. */
  76. int GERBVIEW_FRAME::SelectPCBLayer( int aDefaultLayer, int aCopperLayerCount, wxString aGerberName )
  77. {
  78. SELECT_LAYER_DIALOG* frame =
  79. new SELECT_LAYER_DIALOG( this, aDefaultLayer, aCopperLayerCount, aGerberName );
  80. int layer = frame->ShowModal();
  81. frame->Destroy();
  82. return layer;
  83. }
  84. /*
  85. * The "OK" and "Cancel" buttons are positioned (in a horizontal line)
  86. * beneath the "Layer" radiobox, unless that contains only one column of
  87. * radiobuttons, in which case they are positioned (in a vertical line)
  88. * to the right of that radiobox.
  89. */
  90. SELECT_LAYER_DIALOG::SELECT_LAYER_DIALOG(
  91. GERBVIEW_FRAME* parent, int aDefaultLayer, int aCopperLayerCount, wxString aGerberName )
  92. : DIALOG_SHIM( parent, -1, wxString::Format( _( "Select Layer: %s" ), aGerberName ),
  93. wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER )
  94. {
  95. wxButton* button;
  96. int ii;
  97. wxArrayString layerList;
  98. int selected = -1;
  99. // Store the passed default layer in case the user hits Cancel
  100. m_PassedDefaultLayer = aDefaultLayer;
  101. // Build the layer list; first build copper layers list
  102. int layerCount = 0;
  103. for( ii = FIRST_COPPER_LAYER; ii <= LAST_COPPER_LAYER; ++ii )
  104. {
  105. if( ii == FIRST_COPPER_LAYER || ii == LAST_COPPER_LAYER || ii < aCopperLayerCount-1 )
  106. {
  107. layerList.Add( GetPCBDefaultLayerName( ii ) );
  108. if( aDefaultLayer == ii )
  109. selected = layerCount;
  110. m_layerId.push_back( ii );
  111. layerCount++;
  112. }
  113. }
  114. // Build the layer list; build non copper layers list
  115. for( ; ; ++ii )
  116. {
  117. if( GetPCBDefaultLayerName( ii ) == "" ) // End of list
  118. break;
  119. layerList.Add( GetPCBDefaultLayerName( ii ) );
  120. if( aDefaultLayer == ii )
  121. selected = layerCount;
  122. m_layerId.push_back( ii );
  123. layerCount++;
  124. }
  125. layerList.Add( _( "Hole data" ) );
  126. if( aDefaultLayer == UNDEFINED_LAYER )
  127. selected = layerCount;
  128. m_layerId.push_back( UNDEFINED_LAYER );
  129. layerCount++;
  130. layerList.Add( _( "Do not export" ) );
  131. if( aDefaultLayer == UNSELECTED_LAYER )
  132. selected = layerCount;
  133. m_layerId.push_back( UNSELECTED_LAYER );
  134. layerCount++;
  135. m_layerRadioBox = new wxRadioBox( this, ID_LAYER_SELECT, _( "Layer" ), wxDefaultPosition,
  136. wxDefaultSize, layerList, std::min( layerCount, 12 ),
  137. wxRA_SPECIFY_ROWS );
  138. if( selected >= 0 )
  139. m_layerRadioBox->SetSelection( selected );
  140. wxBoxSizer* mainSizer = new wxBoxSizer( wxHORIZONTAL );
  141. SetSizer( mainSizer );
  142. mainSizer->Add( m_layerRadioBox, 1, wxEXPAND | wxALIGN_TOP | wxALL, 5 );
  143. wxBoxSizer* buttonsSizer = new wxBoxSizer( wxVERTICAL );
  144. mainSizer->Add( buttonsSizer, 0, wxALIGN_BOTTOM | wxALL, 5 );
  145. button = new wxButton( this, wxID_OK, _( "OK" ) );
  146. button->SetDefault();
  147. buttonsSizer->Add( button, 0, wxGROW | wxALL, 5 );
  148. button = new wxButton( this, wxID_CANCEL, _( "Cancel" ) );
  149. buttonsSizer->Add( button, 0, wxGROW | wxALL, 5 );
  150. #ifdef __WXOSX__
  151. // Hack to fix clipped radio buttons on OSX
  152. wxSize size = m_layerRadioBox->GetBestSize() + wxSize( 20, 0 );
  153. m_layerRadioBox->SetMinSize( size );
  154. #endif
  155. GetSizer()->SetSizeHints( this );
  156. Center();
  157. }
  158. void SELECT_LAYER_DIALOG::OnLayerSelected( wxCommandEvent& event )
  159. {
  160. int ii = m_layerId[m_layerRadioBox->GetSelection()];
  161. EndModal( ii );
  162. }
  163. void SELECT_LAYER_DIALOG::OnCancelClick( wxCommandEvent& event )
  164. {
  165. EndModal( m_PassedDefaultLayer );
  166. }
  167. // This function is a duplicate of
  168. // const wxChar* LSET::Name( PCB_LAYER_ID aLayerId )
  169. // However it avoids a dependency to Pcbnew code.
  170. const wxString GetPCBDefaultLayerName( int aLayerId )
  171. {
  172. const wxChar* txt;
  173. // using a switch to explicitly show the mapping more clearly
  174. switch( aLayerId )
  175. {
  176. case F_Cu: txt = wxT( "F.Cu" ); break;
  177. case In1_Cu: txt = wxT( "In1.Cu" ); break;
  178. case In2_Cu: txt = wxT( "In2.Cu" ); break;
  179. case In3_Cu: txt = wxT( "In3.Cu" ); break;
  180. case In4_Cu: txt = wxT( "In4.Cu" ); break;
  181. case In5_Cu: txt = wxT( "In5.Cu" ); break;
  182. case In6_Cu: txt = wxT( "In6.Cu" ); break;
  183. case In7_Cu: txt = wxT( "In7.Cu" ); break;
  184. case In8_Cu: txt = wxT( "In8.Cu" ); break;
  185. case In9_Cu: txt = wxT( "In9.Cu" ); break;
  186. case In10_Cu: txt = wxT( "In10.Cu" ); break;
  187. case In11_Cu: txt = wxT( "In11.Cu" ); break;
  188. case In12_Cu: txt = wxT( "In12.Cu" ); break;
  189. case In13_Cu: txt = wxT( "In13.Cu" ); break;
  190. case In14_Cu: txt = wxT( "In14.Cu" ); break;
  191. case In15_Cu: txt = wxT( "In15.Cu" ); break;
  192. case In16_Cu: txt = wxT( "In16.Cu" ); break;
  193. case In17_Cu: txt = wxT( "In17.Cu" ); break;
  194. case In18_Cu: txt = wxT( "In18.Cu" ); break;
  195. case In19_Cu: txt = wxT( "In19.Cu" ); break;
  196. case In20_Cu: txt = wxT( "In20.Cu" ); break;
  197. case In21_Cu: txt = wxT( "In21.Cu" ); break;
  198. case In22_Cu: txt = wxT( "In22.Cu" ); break;
  199. case In23_Cu: txt = wxT( "In23.Cu" ); break;
  200. case In24_Cu: txt = wxT( "In24.Cu" ); break;
  201. case In25_Cu: txt = wxT( "In25.Cu" ); break;
  202. case In26_Cu: txt = wxT( "In26.Cu" ); break;
  203. case In27_Cu: txt = wxT( "In27.Cu" ); break;
  204. case In28_Cu: txt = wxT( "In28.Cu" ); break;
  205. case In29_Cu: txt = wxT( "In29.Cu" ); break;
  206. case In30_Cu: txt = wxT( "In30.Cu" ); break;
  207. case B_Cu: txt = wxT( "B.Cu" ); break;
  208. // Technicals
  209. case B_Adhes: txt = wxT( "B.Adhes" ); break;
  210. case F_Adhes: txt = wxT( "F.Adhes" ); break;
  211. case B_Paste: txt = wxT( "B.Paste" ); break;
  212. case F_Paste: txt = wxT( "F.Paste" ); break;
  213. case B_SilkS: txt = wxT( "B.SilkS" ); break;
  214. case F_SilkS: txt = wxT( "F.SilkS" ); break;
  215. case B_Mask: txt = wxT( "B.Mask" ); break;
  216. case F_Mask: txt = wxT( "F.Mask" ); break;
  217. // Users
  218. case Dwgs_User: txt = wxT( "Dwgs.User" ); break;
  219. case Cmts_User: txt = wxT( "Cmts.User" ); break;
  220. case Eco1_User: txt = wxT( "Eco1.User" ); break;
  221. case Eco2_User: txt = wxT( "Eco2.User" ); break;
  222. case Edge_Cuts: txt = wxT( "Edge.Cuts" ); break;
  223. // Pcbnew knows some other layers, but any other layer is not suitable for export.
  224. default: // Sentinel
  225. txt = wxT( "" ); break;
  226. }
  227. return wxString( txt );
  228. }