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.

265 lines
9.2 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-2021 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. /**
  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. #include <wx/radiobox.h>
  31. #define NB_PCB_LAYERS PCB_LAYER_ID_COUNT
  32. #define FIRST_COPPER_LAYER 0
  33. #define LAST_COPPER_LAYER 31
  34. // Exported function
  35. const wxString GetPCBDefaultLayerName( int aLayerId );
  36. enum layer_sel_id {
  37. ID_LAYER_SELECT_TOP = 1800,
  38. ID_LAYER_SELECT_BOTTOM,
  39. ID_LAYER_SELECT
  40. };
  41. class SELECT_LAYER_DIALOG : public DIALOG_SHIM
  42. {
  43. public:
  44. SELECT_LAYER_DIALOG( GERBVIEW_FRAME* parent, int aDefaultLayer, int aCopperLayerCount,
  45. wxString aGerberName );
  46. ~SELECT_LAYER_DIALOG() { };
  47. int GetSelectedLayer() { return m_selectedLayer; }
  48. protected:
  49. bool TransferDataFromWindow() override;
  50. private:
  51. void OnLayerSelected( wxCommandEvent& event );
  52. DECLARE_EVENT_TABLE()
  53. int m_selectedLayer;
  54. wxRadioBox* m_layerRadioBox;
  55. std::vector <int> m_layerId;
  56. };
  57. BEGIN_EVENT_TABLE( SELECT_LAYER_DIALOG, wxDialog )
  58. EVT_RADIOBOX( ID_LAYER_SELECT, SELECT_LAYER_DIALOG::OnLayerSelected )
  59. END_EVENT_TABLE()
  60. int GERBVIEW_FRAME::SelectPCBLayer( int aDefaultLayer, int aCopperLayerCount, wxString aGerberName )
  61. {
  62. SELECT_LAYER_DIALOG* frame =
  63. new SELECT_LAYER_DIALOG( this, aDefaultLayer, aCopperLayerCount, aGerberName );
  64. frame->ShowModal();
  65. frame->Destroy();
  66. return frame->GetSelectedLayer();
  67. }
  68. SELECT_LAYER_DIALOG::SELECT_LAYER_DIALOG( GERBVIEW_FRAME* parent, int aDefaultLayer,
  69. int aCopperLayerCount, wxString aGerberName )
  70. : DIALOG_SHIM( parent, -1, wxString::Format( _( "Select Layer: %s" ), aGerberName ),
  71. wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER )
  72. {
  73. wxButton* button;
  74. int ii;
  75. wxArrayString layerList;
  76. int selected = -1;
  77. // Store the passed default layer in case the user hits Cancel
  78. m_selectedLayer = aDefaultLayer;
  79. // Build the layer list; first build copper layers list
  80. int layerCount = 0;
  81. for( ii = FIRST_COPPER_LAYER; ii <= LAST_COPPER_LAYER; ++ii )
  82. {
  83. if( ii == FIRST_COPPER_LAYER || ii == LAST_COPPER_LAYER || ii < aCopperLayerCount-1 )
  84. {
  85. layerList.Add( GetPCBDefaultLayerName( ii ) );
  86. if( aDefaultLayer == ii )
  87. selected = layerCount;
  88. m_layerId.push_back( ii );
  89. layerCount++;
  90. }
  91. }
  92. // Build the layer list; build non copper layers list
  93. for( ; ; ++ii )
  94. {
  95. if( GetPCBDefaultLayerName( ii ) == "" ) // End of list
  96. break;
  97. layerList.Add( GetPCBDefaultLayerName( ii ) );
  98. if( aDefaultLayer == ii )
  99. selected = layerCount;
  100. m_layerId.push_back( ii );
  101. layerCount++;
  102. }
  103. layerList.Add( _( "Hole data" ) );
  104. if( aDefaultLayer == UNDEFINED_LAYER )
  105. selected = layerCount;
  106. m_layerId.push_back( UNDEFINED_LAYER );
  107. layerCount++;
  108. layerList.Add( _( "Do not export" ) );
  109. if( aDefaultLayer == UNSELECTED_LAYER )
  110. selected = layerCount;
  111. m_layerId.push_back( UNSELECTED_LAYER );
  112. layerCount++;
  113. m_layerRadioBox = new wxRadioBox( this, ID_LAYER_SELECT, _( "Layer" ), wxDefaultPosition,
  114. wxDefaultSize, layerList, std::min( layerCount, 12 ),
  115. wxRA_SPECIFY_ROWS );
  116. if( selected >= 0 )
  117. m_layerRadioBox->SetSelection( selected );
  118. wxBoxSizer* mainSizer = new wxBoxSizer( wxHORIZONTAL );
  119. SetSizer( mainSizer );
  120. mainSizer->Add( m_layerRadioBox, 1, wxEXPAND | wxALIGN_TOP | wxALL, 5 );
  121. wxBoxSizer* buttonsSizer = new wxBoxSizer( wxVERTICAL );
  122. mainSizer->Add( buttonsSizer, 0, wxALIGN_BOTTOM | wxALL, 5 );
  123. button = new wxButton( this, wxID_OK, _( "OK" ) );
  124. button->SetDefault();
  125. buttonsSizer->Add( button, 0, wxGROW | wxALL, 5 );
  126. button = new wxButton( this, wxID_CANCEL, _( "Cancel" ) );
  127. buttonsSizer->Add( button, 0, wxGROW | wxALL, 5 );
  128. #ifdef __WXOSX__
  129. // Hack to fix clipped radio buttons on OSX
  130. wxSize size = m_layerRadioBox->GetBestSize() + wxSize( 20, 0 );
  131. m_layerRadioBox->SetMinSize( size );
  132. #endif
  133. GetSizer()->SetSizeHints( this );
  134. Center();
  135. }
  136. void SELECT_LAYER_DIALOG::OnLayerSelected( wxCommandEvent& event )
  137. {
  138. wxPostEvent( this, wxCommandEvent( wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK ) );
  139. }
  140. bool SELECT_LAYER_DIALOG::TransferDataFromWindow()
  141. {
  142. if( !wxDialog::TransferDataFromWindow() )
  143. return false;
  144. m_selectedLayer = m_layerId[m_layerRadioBox->GetSelection()];
  145. return true;
  146. }
  147. // This function is a duplicate of
  148. // const wxChar* LSET::Name( PCB_LAYER_ID aLayerId )
  149. // However it avoids a dependency to Pcbnew code.
  150. const wxString GetPCBDefaultLayerName( int aLayerId )
  151. {
  152. const wxChar* txt;
  153. // using a switch to explicitly show the mapping more clearly
  154. switch( aLayerId )
  155. {
  156. case F_Cu: txt = wxT( "F.Cu" ); break;
  157. case In1_Cu: txt = wxT( "In1.Cu" ); break;
  158. case In2_Cu: txt = wxT( "In2.Cu" ); break;
  159. case In3_Cu: txt = wxT( "In3.Cu" ); break;
  160. case In4_Cu: txt = wxT( "In4.Cu" ); break;
  161. case In5_Cu: txt = wxT( "In5.Cu" ); break;
  162. case In6_Cu: txt = wxT( "In6.Cu" ); break;
  163. case In7_Cu: txt = wxT( "In7.Cu" ); break;
  164. case In8_Cu: txt = wxT( "In8.Cu" ); break;
  165. case In9_Cu: txt = wxT( "In9.Cu" ); break;
  166. case In10_Cu: txt = wxT( "In10.Cu" ); break;
  167. case In11_Cu: txt = wxT( "In11.Cu" ); break;
  168. case In12_Cu: txt = wxT( "In12.Cu" ); break;
  169. case In13_Cu: txt = wxT( "In13.Cu" ); break;
  170. case In14_Cu: txt = wxT( "In14.Cu" ); break;
  171. case In15_Cu: txt = wxT( "In15.Cu" ); break;
  172. case In16_Cu: txt = wxT( "In16.Cu" ); break;
  173. case In17_Cu: txt = wxT( "In17.Cu" ); break;
  174. case In18_Cu: txt = wxT( "In18.Cu" ); break;
  175. case In19_Cu: txt = wxT( "In19.Cu" ); break;
  176. case In20_Cu: txt = wxT( "In20.Cu" ); break;
  177. case In21_Cu: txt = wxT( "In21.Cu" ); break;
  178. case In22_Cu: txt = wxT( "In22.Cu" ); break;
  179. case In23_Cu: txt = wxT( "In23.Cu" ); break;
  180. case In24_Cu: txt = wxT( "In24.Cu" ); break;
  181. case In25_Cu: txt = wxT( "In25.Cu" ); break;
  182. case In26_Cu: txt = wxT( "In26.Cu" ); break;
  183. case In27_Cu: txt = wxT( "In27.Cu" ); break;
  184. case In28_Cu: txt = wxT( "In28.Cu" ); break;
  185. case In29_Cu: txt = wxT( "In29.Cu" ); break;
  186. case In30_Cu: txt = wxT( "In30.Cu" ); break;
  187. case B_Cu: txt = wxT( "B.Cu" ); break;
  188. // Technicals
  189. case B_Adhes: txt = wxT( "B.Adhes" ); break;
  190. case F_Adhes: txt = wxT( "F.Adhes" ); break;
  191. case B_Paste: txt = wxT( "B.Paste" ); break;
  192. case F_Paste: txt = wxT( "F.Paste" ); break;
  193. case B_SilkS: txt = wxT( "B.SilkS" ); break;
  194. case F_SilkS: txt = wxT( "F.SilkS" ); break;
  195. case B_Mask: txt = wxT( "B.Mask" ); break;
  196. case F_Mask: txt = wxT( "F.Mask" ); break;
  197. // Users
  198. case Dwgs_User: txt = wxT( "Dwgs.User" ); break;
  199. case Cmts_User: txt = wxT( "Cmts.User" ); break;
  200. case Eco1_User: txt = wxT( "Eco1.User" ); break;
  201. case Eco2_User: txt = wxT( "Eco2.User" ); break;
  202. case Edge_Cuts: txt = wxT( "Edge.Cuts" ); break;
  203. // Pcbnew knows some other layers, but any other layer is not suitable for export.
  204. default: // Sentinel
  205. txt = wxT( "" ); break;
  206. }
  207. return wxString( txt );
  208. }