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.

148 lines
4.8 KiB

12 years ago
4 years ago
4 years ago
4 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 1992-2015 Jean-Pierre Charras <jean-pierre.charras@ujf-grenoble.fr>
  5. * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
  6. * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, you may find one here:
  20. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  21. * or you may search the http://www.gnu.org website for the version 2 license,
  22. * or you may write to the Free Software Foundation, Inc.,
  23. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  24. */
  25. #include <pgm_base.h>
  26. #include <settings/settings_manager.h>
  27. #include <footprint_editor_settings.h>
  28. #include <pcb_edit_frame.h>
  29. #include <layer_ids.h>
  30. #include <settings/color_settings.h>
  31. #include <board.h>
  32. #include <pcb_layer_box_selector.h>
  33. #include <tools/pcb_actions.h>
  34. #include <dpi_scaling_common.h>
  35. // class to display a layer list in a wxBitmapComboBox.
  36. // Reload the Layers
  37. void PCB_LAYER_BOX_SELECTOR::Resync()
  38. {
  39. Freeze();
  40. Clear();
  41. #ifdef __WXMSW__
  42. DPI_SCALING_COMMON dpi( nullptr, this );
  43. int size = static_cast<int>( 14 / dpi.GetContentScaleFactor() );
  44. #else
  45. const int size = 14;
  46. #endif
  47. LSET show = LSET::AllLayersMask() & ~m_layerMaskDisable;
  48. LSET activated = getEnabledLayers() & ~m_layerMaskDisable;
  49. wxString layerstatus;
  50. for( PCB_LAYER_ID layerid : show.UIOrder() )
  51. {
  52. if( !m_showNotEnabledBrdlayers && !activated[layerid] )
  53. continue;
  54. else if( !activated[layerid] )
  55. layerstatus = wxT( " " ) + _( "(not activated)" );
  56. else
  57. layerstatus.Empty();
  58. wxBitmap bmp( size, size );
  59. DrawColorSwatch( bmp, getLayerColor( LAYER_PCB_BACKGROUND ), getLayerColor( layerid ) );
  60. wxString layername = getLayerName( layerid ) + layerstatus;
  61. if( m_layerhotkeys )
  62. {
  63. TOOL_ACTION* action = PCB_ACTIONS::LayerIDToAction( layerid );
  64. if( action )
  65. layername = AddHotkeyName( layername, action->GetHotKey(), IS_COMMENT );
  66. }
  67. Append( layername, bmp, (void*)(intptr_t) layerid );
  68. }
  69. if( !m_undefinedLayerName.IsEmpty() )
  70. Append( m_undefinedLayerName, wxNullBitmap, (void*)(intptr_t)UNDEFINED_LAYER );
  71. // Ensure the size of the widget is enough to show the text and the icon
  72. // We have to have a selected item when doing this, because otherwise GTK
  73. // will just choose a random size that might not fit the actual data
  74. // (such as in cases where the font size is very large). So we select
  75. // the first item, get the size of the control and make that the minimum size,
  76. // then remove the selection (which was the initial state).
  77. SetSelection( 0 );
  78. SetMinSize( wxSize( -1, -1 ) );
  79. wxSize bestSize = GetBestSize();
  80. bestSize.x = GetBestSize().x + size + 10;
  81. SetMinSize( bestSize );
  82. SetSelection( wxNOT_FOUND );
  83. Fit();
  84. Thaw();
  85. }
  86. // Returns true if the layer id is enabled (i.e. is it should be displayed)
  87. bool PCB_LAYER_BOX_SELECTOR::isLayerEnabled( int aLayer ) const
  88. {
  89. return getEnabledLayers().test( aLayer );
  90. }
  91. LSET PCB_LAYER_BOX_SELECTOR::getEnabledLayers() const
  92. {
  93. static LSET footprintEditorLayers = LSET::AllLayersMask() & ~LSET::ForbiddenFootprintLayers();
  94. if( m_boardFrame )
  95. return m_boardFrame->GetBoard()->GetEnabledLayers();
  96. else
  97. return footprintEditorLayers;
  98. }
  99. // Returns a color index from the layer id
  100. COLOR4D PCB_LAYER_BOX_SELECTOR::getLayerColor( int aLayer ) const
  101. {
  102. if( m_boardFrame )
  103. {
  104. return m_boardFrame->GetColorSettings()->GetColor( aLayer );
  105. }
  106. else
  107. {
  108. SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager();
  109. FOOTPRINT_EDITOR_SETTINGS* settings = mgr.GetAppSettings<FOOTPRINT_EDITOR_SETTINGS>();
  110. COLOR_SETTINGS* current = mgr.GetColorSettings( settings->m_ColorTheme );
  111. return current->GetColor( aLayer );
  112. }
  113. }
  114. // Returns the name of the layer id
  115. wxString PCB_LAYER_BOX_SELECTOR::getLayerName( int aLayer ) const
  116. {
  117. if( m_boardFrame )
  118. return m_boardFrame->GetBoard()->GetLayerName( ToLAYER_ID( aLayer ) );
  119. else
  120. return BOARD::GetStandardLayerName( ToLAYER_ID( aLayer ) );
  121. }