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.

349 lines
11 KiB

  1. /**
  2. * @file sel_layer.cpp
  3. * @brief Set up the basic primitives for Layer control.
  4. */
  5. #include <fctsys.h>
  6. #include <common.h>
  7. #include <class_drawpanel.h>
  8. #include <confirm.h>
  9. #include <wxBasePcbFrame.h>
  10. #include <pcbcommon.h>
  11. #include <class_board.h>
  12. enum layer_sel_id {
  13. ID_LAYER_SELECT_TOP = 1800,
  14. ID_LAYER_SELECT_BOTTOM,
  15. ID_LAYER_SELECT
  16. };
  17. class SELECT_LAYER_DIALOG : public wxDialog
  18. {
  19. private:
  20. PCB_BASE_FRAME* m_Parent;
  21. wxRadioBox* m_LayerList;
  22. int m_LayerId[NB_LAYERS + 1]; // One extra element for "(Deselect)" radiobutton
  23. public:
  24. // Constructor and destructor
  25. SELECT_LAYER_DIALOG( PCB_BASE_FRAME* parent, int default_layer,
  26. int min_layer, int max_layer, bool null_layer );
  27. ~SELECT_LAYER_DIALOG() { };
  28. private:
  29. void OnLayerSelected( wxCommandEvent& event );
  30. void OnCancelClick( wxCommandEvent& event );
  31. DECLARE_EVENT_TABLE()
  32. };
  33. BEGIN_EVENT_TABLE( SELECT_LAYER_DIALOG, wxDialog )
  34. EVT_BUTTON( wxID_OK, SELECT_LAYER_DIALOG::OnLayerSelected )
  35. EVT_BUTTON( wxID_CANCEL, SELECT_LAYER_DIALOG::OnCancelClick )
  36. EVT_RADIOBOX( ID_LAYER_SELECT, SELECT_LAYER_DIALOG::OnLayerSelected )
  37. END_EVENT_TABLE()
  38. /** Install the dialog box for layer selection
  39. * @param default_layer = Preselection (NB_LAYERS for "(Deselect)" layer)
  40. * @param min_layer = min layer value (-1 if no min value)
  41. * @param max_layer = max layer value (-1 if no max value)
  42. * @param null_layer = display a "(Deselect)" radiobutton (when set to true)
  43. * @return new layer value (NB_LAYERS when "(Deselect)" radiobutton selected),
  44. * or -1 if canceled
  45. *
  46. * Providing the option to also display a "(Deselect)" radiobutton makes the
  47. * "Swap Layers" command (and GerbView's "Export to Pcbnew" command) more "user
  48. * friendly", by permitting any layer to be "deselected" immediately after its
  49. * corresponding radiobutton has been clicked on. (It would otherwise be
  50. * necessary to first cancel the "Select Layer:" dialog box (invoked after a
  51. * different radiobutton is clicked on) prior to then clicking on the
  52. * "Deselect"
  53. * button provided within the "Swap Layers:" or "Layer selection:" dialog box).
  54. */
  55. int PCB_BASE_FRAME::SelectLayer( int default_layer,
  56. int min_layer,
  57. int max_layer,
  58. bool null_layer )
  59. {
  60. int layer;
  61. SELECT_LAYER_DIALOG* frame = new SELECT_LAYER_DIALOG( this,
  62. default_layer,
  63. min_layer,
  64. max_layer,
  65. null_layer );
  66. layer = frame->ShowModal();
  67. frame->Destroy();
  68. return layer;
  69. }
  70. /*
  71. * The "OK" and "Cancel" buttons are positioned (in a horizontal line)
  72. * beneath the "Layer" radiobox, unless that contains only one column of
  73. * radiobuttons, in which case they are positioned (in a vertical line)
  74. * to the right of that radiobox.
  75. */
  76. SELECT_LAYER_DIALOG::SELECT_LAYER_DIALOG( PCB_BASE_FRAME* parent,
  77. int default_layer, int min_layer,
  78. int max_layer, bool null_layer ) :
  79. wxDialog( parent, -1, _( "Select Layer:" ), wxPoint( -1, -1 ),
  80. wxSize( 470, 250 ),
  81. DIALOG_STYLE )
  82. {
  83. BOARD* board = parent->GetBoard();
  84. wxButton* Button;
  85. int ii;
  86. wxString LayerList[NB_LAYERS + 1]; // One extra element for "(Deselect)"
  87. // radiobutton
  88. int LayerCount, LayerSelect = -1;
  89. m_Parent = parent;
  90. /* Build the layer list */
  91. LayerCount = 0;
  92. int Masque_Layer = g_TabAllCopperLayerMask[board->GetCopperLayerCount() - 1];
  93. Masque_Layer += ALL_NO_CU_LAYERS;
  94. for( ii = 0; ii < NB_LAYERS; ii++ )
  95. {
  96. m_LayerId[ii] = 0;
  97. if( GetLayerMask( ii ) & Masque_Layer )
  98. {
  99. if( min_layer > ii )
  100. continue;
  101. if( ( max_layer >= 0 ) && ( max_layer < ii ) )
  102. break;
  103. LayerList[LayerCount] = board->GetLayerName( ii );
  104. if( ii == default_layer )
  105. LayerSelect = LayerCount;
  106. m_LayerId[LayerCount] = ii;
  107. LayerCount++;
  108. }
  109. }
  110. // When appropriate, also provide a "(Deselect)" radiobutton
  111. if( null_layer )
  112. {
  113. LayerList[LayerCount] = _( "(Deselect)" );
  114. if( NB_LAYERS == default_layer )
  115. LayerSelect = LayerCount;
  116. m_LayerId[LayerCount] = NB_LAYERS;
  117. LayerCount++;
  118. }
  119. m_LayerList = new wxRadioBox( this, ID_LAYER_SELECT, _( "Layer" ),
  120. wxPoint( -1, -1 ), wxSize( -1, -1 ),
  121. LayerCount, LayerList,
  122. (LayerCount < 8) ? LayerCount : 8,
  123. wxRA_SPECIFY_ROWS );
  124. if( LayerSelect >= 0 )
  125. m_LayerList->SetSelection( LayerSelect );
  126. wxBoxSizer* FrameBoxSizer = new wxBoxSizer( wxHORIZONTAL );
  127. SetSizer( FrameBoxSizer );
  128. FrameBoxSizer->Add( m_LayerList, 0, wxALIGN_TOP | wxALL, 5 );
  129. wxBoxSizer* ButtonBoxSizer = new wxBoxSizer( wxVERTICAL );
  130. FrameBoxSizer->Add( ButtonBoxSizer, 0, wxALIGN_BOTTOM | wxALL, 0 );
  131. Button = new wxButton( this, wxID_OK, _( "OK" ) );
  132. Button->SetDefault();
  133. ButtonBoxSizer->Add( Button, 0, wxGROW | wxALL, 5 );
  134. Button = new wxButton( this, wxID_CANCEL, _( "Cancel" ) );
  135. ButtonBoxSizer->Add( Button, 0, wxGROW | wxALL, 5 );
  136. SetFocus();
  137. GetSizer()->SetSizeHints( this );
  138. Center();
  139. }
  140. void SELECT_LAYER_DIALOG::OnLayerSelected( wxCommandEvent& event )
  141. {
  142. int ii = m_LayerId[m_LayerList->GetSelection()];
  143. EndModal( ii );
  144. }
  145. void SELECT_LAYER_DIALOG::OnCancelClick( wxCommandEvent& event )
  146. {
  147. EndModal( -1 );
  148. }
  149. /*********************************************/
  150. /* Dialog for the selecting pairs of layers. */
  151. /*********************************************/
  152. class SELECT_LAYERS_PAIR_DIALOG : public wxDialog
  153. {
  154. private:
  155. PCB_BASE_FRAME* m_Parent;
  156. wxRadioBox* m_LayerListTOP;
  157. wxRadioBox* m_LayerListBOTTOM;
  158. int m_LayerId[NB_COPPER_LAYERS];
  159. public: SELECT_LAYERS_PAIR_DIALOG( PCB_BASE_FRAME* parent );
  160. ~SELECT_LAYERS_PAIR_DIALOG() { };
  161. private:
  162. void OnOkClick( wxCommandEvent& event );
  163. void OnCancelClick( wxCommandEvent& event );
  164. DECLARE_EVENT_TABLE()
  165. };
  166. BEGIN_EVENT_TABLE( SELECT_LAYERS_PAIR_DIALOG, wxDialog )
  167. EVT_BUTTON( wxID_OK, SELECT_LAYERS_PAIR_DIALOG::OnOkClick )
  168. EVT_BUTTON( wxID_CANCEL, SELECT_LAYERS_PAIR_DIALOG::OnCancelClick )
  169. END_EVENT_TABLE()
  170. /* Display a list of two copper layers for selection of a pair of layers
  171. * for auto-routing, vias ...
  172. */
  173. void PCB_BASE_FRAME::SelectLayerPair()
  174. {
  175. // Check whether more than one copper layer has been enabled for the
  176. // current PCB file, as Layer Pairs can only meaningfully be defined
  177. // within PCB files which contain at least two copper layers.
  178. if( GetBoard()->GetCopperLayerCount() < 2 )
  179. {
  180. wxString InfoMsg;
  181. InfoMsg = _( "Less than two copper layers are being used." );
  182. InfoMsg << wxT( "\n" ) << _( "Hence layer pairs cannot be specified." );
  183. DisplayInfoMessage( this, InfoMsg );
  184. return;
  185. }
  186. SELECT_LAYERS_PAIR_DIALOG* frame = new SELECT_LAYERS_PAIR_DIALOG( this );
  187. int result = frame->ShowModal();
  188. frame->Destroy();
  189. m_canvas->MoveCursorToCrossHair();
  190. // if user changed colors and we are in high contrast mode, then redraw
  191. // because the PAD_SMD pads may change color.
  192. if( result >= 0 && DisplayOpt.ContrastModeDisplay )
  193. {
  194. m_canvas->Refresh();
  195. }
  196. }
  197. SELECT_LAYERS_PAIR_DIALOG::SELECT_LAYERS_PAIR_DIALOG( PCB_BASE_FRAME* parent ) :
  198. wxDialog( parent, -1, _( "Select Layer Pair:" ), wxPoint( -1, -1 ),
  199. wxSize( 470, 250 ), DIALOG_STYLE )
  200. {
  201. BOARD* board = parent->GetBoard();
  202. wxButton* Button;
  203. int ii, LayerCount;
  204. wxString LayerList[NB_COPPER_LAYERS];
  205. int LayerTopSelect = 0, LayerBottomSelect = 0;
  206. m_Parent = parent;
  207. PCB_SCREEN* screen = (PCB_SCREEN*) m_Parent->GetScreen();
  208. int Masque_Layer = g_TabAllCopperLayerMask[board->GetCopperLayerCount() - 1];
  209. Masque_Layer += ALL_NO_CU_LAYERS;
  210. for( ii = 0, LayerCount = 0; ii < NB_COPPER_LAYERS; ii++ )
  211. {
  212. m_LayerId[ii] = 0;
  213. if( (GetLayerMask( ii ) & Masque_Layer) )
  214. {
  215. LayerList[LayerCount] = board->GetLayerName( ii );
  216. if( ii == screen->m_Route_Layer_TOP )
  217. LayerTopSelect = LayerCount;
  218. if( ii == screen->m_Route_Layer_BOTTOM )
  219. LayerBottomSelect = LayerCount;
  220. m_LayerId[LayerCount] = ii;
  221. LayerCount++;
  222. }
  223. }
  224. m_LayerListTOP = new wxRadioBox( this, ID_LAYER_SELECT_TOP,
  225. _( "Top Layer" ),
  226. wxPoint( -1, -1 ), wxSize( -1, -1 ),
  227. LayerCount, LayerList,
  228. (LayerCount < 8) ? LayerCount : 8,
  229. wxRA_SPECIFY_ROWS );
  230. m_LayerListTOP->SetSelection( LayerTopSelect );
  231. m_LayerListBOTTOM = new wxRadioBox( this, ID_LAYER_SELECT_BOTTOM,
  232. _( "Bottom Layer" ),
  233. wxPoint( -1, -1 ), wxSize( -1, -1 ),
  234. LayerCount, LayerList,
  235. (LayerCount < 8) ? LayerCount : 8,
  236. wxRA_SPECIFY_ROWS );
  237. m_LayerListBOTTOM->SetSelection( LayerBottomSelect );
  238. wxBoxSizer* FrameBoxSizer = new wxBoxSizer( wxVERTICAL );
  239. SetSizer( FrameBoxSizer );
  240. wxBoxSizer* RadioBoxSizer = new wxBoxSizer( wxHORIZONTAL );
  241. FrameBoxSizer->Add( RadioBoxSizer, 0, wxALIGN_LEFT | wxALL, 0 );
  242. wxBoxSizer* ButtonBoxSizer = new wxBoxSizer( wxHORIZONTAL );
  243. FrameBoxSizer->Add( ButtonBoxSizer, 0, wxALIGN_RIGHT | wxALL, 0 );
  244. RadioBoxSizer->Add( m_LayerListTOP, 0, wxALIGN_TOP | wxALL, 5 );
  245. RadioBoxSizer->Add( m_LayerListBOTTOM, 0, wxALIGN_TOP | wxALL, 5 );
  246. Button = new wxButton( this, wxID_OK, _( "OK" ) );
  247. Button->SetDefault();
  248. ButtonBoxSizer->Add( Button, 0, wxGROW | wxALL, 5 );
  249. Button = new wxButton( this, wxID_CANCEL, _( "Cancel" ) );
  250. ButtonBoxSizer->Add( Button, 0, wxGROW | wxALL, 5 );
  251. SetFocus();
  252. GetSizer()->SetSizeHints( this );
  253. Center();
  254. }
  255. void SELECT_LAYERS_PAIR_DIALOG::OnOkClick( wxCommandEvent& event )
  256. {
  257. // select the same layer for top and bottom is allowed (normal in some
  258. // boards)
  259. // but could be a mistake. So display an info message
  260. if( m_LayerId[m_LayerListTOP->GetSelection()] == m_LayerId[m_LayerListBOTTOM->GetSelection()] )
  261. DisplayInfoMessage( this,
  262. _( "Warning: The Top Layer and Bottom Layer are same." ) );
  263. PCB_SCREEN* screen = (PCB_SCREEN*) m_Parent->GetScreen();
  264. screen->m_Route_Layer_TOP = m_LayerId[m_LayerListTOP->GetSelection()];
  265. screen->m_Route_Layer_BOTTOM = m_LayerId[m_LayerListBOTTOM->GetSelection()];
  266. EndModal( 0 );
  267. }
  268. void SELECT_LAYERS_PAIR_DIALOG::OnCancelClick( wxCommandEvent& event )
  269. {
  270. EndModal( -1 );
  271. }