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.

165 lines
5.1 KiB

8 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
  1. /**
  2. * @file class_pcb_layer_box_selector.cpp
  3. * @brief a derived class of LAYER_BOX_SELECTOR to handle the layer box selector
  4. * in Pcbnew
  5. */
  6. /*
  7. * This program source code file is part of KiCad, a free EDA CAD application.
  8. *
  9. * Copyright (C) 1992-2015 Jean-Pierre Charras <jean-pierre.charras@ujf-grenoble.fr>
  10. * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
  11. * Copyright (C) 1992-2018 KiCad Developers, see AUTHORS.txt for contributors.
  12. *
  13. * This program is free software; you can redistribute it and/or
  14. * modify it under the terms of the GNU General Public License
  15. * as published by the Free Software Foundation; either version 2
  16. * of the License, or (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program; if not, you may find one here:
  25. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  26. * or you may search the http://www.gnu.org website for the version 2 license,
  27. * or you may write to the Free Software Foundation, Inc.,
  28. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  29. */
  30. #include <common.h>
  31. #include <pcbnew.h>
  32. #include <pcb_edit_frame.h>
  33. #include <board_design_settings.h>
  34. #include <layers_id_colors_and_visibility.h>
  35. #include <class_board.h>
  36. #include <hotkeys.h>
  37. #include <pcb_layer_box_selector.h>
  38. // translate aLayer to its hotkey
  39. static int layer2hotkey_id( PCB_LAYER_ID aLayer )
  40. {
  41. switch( aLayer )
  42. {
  43. case F_Cu: return HK_SWITCH_LAYER_TO_COMPONENT;
  44. case B_Cu: return HK_SWITCH_LAYER_TO_COPPER;
  45. case In1_Cu: return HK_SWITCH_LAYER_TO_INNER1;
  46. case In2_Cu: return HK_SWITCH_LAYER_TO_INNER2;
  47. case In3_Cu: return HK_SWITCH_LAYER_TO_INNER3;
  48. case In4_Cu: return HK_SWITCH_LAYER_TO_INNER4;
  49. case In5_Cu: return HK_SWITCH_LAYER_TO_INNER5;
  50. case In6_Cu: return HK_SWITCH_LAYER_TO_INNER6;
  51. case In7_Cu: return HK_SWITCH_LAYER_TO_INNER7;
  52. case In8_Cu: return HK_SWITCH_LAYER_TO_INNER8;
  53. case In9_Cu: return HK_SWITCH_LAYER_TO_INNER9;
  54. case In10_Cu: return HK_SWITCH_LAYER_TO_INNER10;
  55. case In11_Cu: return HK_SWITCH_LAYER_TO_INNER11;
  56. case In12_Cu: return HK_SWITCH_LAYER_TO_INNER12;
  57. case In13_Cu: return HK_SWITCH_LAYER_TO_INNER13;
  58. case In14_Cu: return HK_SWITCH_LAYER_TO_INNER14;
  59. default:
  60. return -1;
  61. }
  62. }
  63. // class to display a layer list in a wxBitmapComboBox.
  64. // Reload the Layers
  65. void PCB_LAYER_BOX_SELECTOR::Resync()
  66. {
  67. Clear();
  68. // Tray to fix a minimum width fot the BitmapComboBox
  69. int minwidth = 80;
  70. wxClientDC dc( GetParent() ); // The DC for "this" is not always initialized
  71. const int BM_SIZE = 14;
  72. LSET show = LSET::AllLayersMask() & ~m_layerMaskDisable;
  73. LSET activated = getEnabledLayers() & ~m_layerMaskDisable;
  74. wxString layerstatus;
  75. for( LSEQ seq = show.UIOrder(); seq; ++seq )
  76. {
  77. PCB_LAYER_ID layerid = *seq;
  78. if( !m_showNotEnabledBrdlayers && !activated[layerid] )
  79. continue;
  80. else if( !activated[layerid] )
  81. layerstatus = wxT( " " ) + _( "(not activated)" );
  82. else
  83. layerstatus.Empty();
  84. wxBitmap bmp( BM_SIZE, BM_SIZE );
  85. DrawColorSwatch( bmp, GetLayerColor( LAYER_PCB_BACKGROUND ), GetLayerColor( layerid ) );
  86. wxString layername = GetLayerName( layerid ) + layerstatus;
  87. if( m_layerhotkeys && m_hotkeys )
  88. {
  89. int id = layer2hotkey_id( layerid );
  90. if( id != -1 )
  91. layername = AddHotkeyName( layername, m_hotkeys, id, IS_COMMENT );
  92. }
  93. Append( layername, bmp, (void*)(intptr_t) layerid );
  94. int w, h;
  95. dc.GetTextExtent ( layername, &w, &h );
  96. minwidth = std::max( minwidth, w );
  97. }
  98. // Approximate bitmap size and margins
  99. minwidth += BM_SIZE + 32 + ConvertDialogToPixels( wxSize( 8, 0 ) ).x;
  100. SetMinSize( wxSize( minwidth, -1 ) );
  101. }
  102. // Returns true if the layer id is enabled (i.e. is it should be displayed)
  103. bool PCB_LAYER_BOX_SELECTOR::IsLayerEnabled( LAYER_NUM aLayer ) const
  104. {
  105. wxASSERT( m_boardFrame != NULL );
  106. BOARD* board = m_boardFrame->GetBoard();
  107. wxASSERT( board != NULL );
  108. return board->IsLayerEnabled( ToLAYER_ID( aLayer ) );
  109. }
  110. LSET PCB_LAYER_BOX_SELECTOR::getEnabledLayers() const
  111. {
  112. wxASSERT( m_boardFrame != NULL );
  113. BOARD* board = m_boardFrame->GetBoard();
  114. wxASSERT( board != NULL );
  115. return board->GetEnabledLayers();
  116. }
  117. // Returns a color index from the layer id
  118. COLOR4D PCB_LAYER_BOX_SELECTOR::GetLayerColor( LAYER_NUM aLayer ) const
  119. {
  120. wxASSERT( m_boardFrame );
  121. return m_boardFrame->Settings().Colors().GetLayerColor( aLayer );
  122. }
  123. // Returns the name of the layer id
  124. wxString PCB_LAYER_BOX_SELECTOR::GetLayerName( LAYER_NUM aLayer ) const
  125. {
  126. wxASSERT( m_boardFrame );
  127. BOARD* board = m_boardFrame->GetBoard();
  128. wxASSERT( board );
  129. return board->GetLayerName( ToLAYER_ID( aLayer ) );
  130. }