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.

146 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. // class to display a layer list in a wxBitmapComboBox.
  35. // Reload the Layers
  36. void PCB_LAYER_BOX_SELECTOR::Resync()
  37. {
  38. Freeze();
  39. Clear();
  40. #ifdef __WXMSW__
  41. DPI_SCALING dpi( nullptr, this );
  42. int size = static_cast<int>( 14 / dpi.GetContentScaleFactor() );
  43. #else
  44. const int size = 14;
  45. #endif
  46. LSET show = LSET::AllLayersMask() & ~m_layerMaskDisable;
  47. LSET activated = getEnabledLayers() & ~m_layerMaskDisable;
  48. wxString layerstatus;
  49. for( PCB_LAYER_ID layerid : show.UIOrder() )
  50. {
  51. if( !m_showNotEnabledBrdlayers && !activated[layerid] )
  52. continue;
  53. else if( !activated[layerid] )
  54. layerstatus = wxT( " " ) + _( "(not activated)" );
  55. else
  56. layerstatus.Empty();
  57. wxBitmap bmp( size, size );
  58. DrawColorSwatch( bmp, getLayerColor( LAYER_PCB_BACKGROUND ), getLayerColor( layerid ) );
  59. wxString layername = getLayerName( layerid ) + layerstatus;
  60. if( m_layerhotkeys )
  61. {
  62. TOOL_ACTION* action = PCB_ACTIONS::LayerIDToAction( layerid );
  63. if( action )
  64. layername = AddHotkeyName( layername, action->GetHotKey(), IS_COMMENT );
  65. }
  66. Append( layername, bmp, (void*)(intptr_t) layerid );
  67. }
  68. if( !m_undefinedLayerName.IsEmpty() )
  69. Append( m_undefinedLayerName, wxNullBitmap, (void*)(intptr_t)UNDEFINED_LAYER );
  70. // Ensure the size of the widget is enough to show the text and the icon
  71. // We have to have a selected item when doing this, because otherwise GTK
  72. // will just choose a random size that might not fit the actual data
  73. // (such as in cases where the font size is very large). So we select
  74. // the first item, get the size of the control and make that the minimum size,
  75. // then remove the selection (which was the initial state).
  76. SetSelection( 0 );
  77. SetMinSize( wxSize( -1, -1 ) );
  78. wxSize bestSize = GetBestSize();
  79. bestSize.x = GetBestSize().x + size + 10;
  80. SetMinSize( bestSize );
  81. SetSelection( wxNOT_FOUND );
  82. Thaw();
  83. }
  84. // Returns true if the layer id is enabled (i.e. is it should be displayed)
  85. bool PCB_LAYER_BOX_SELECTOR::isLayerEnabled( int aLayer ) const
  86. {
  87. return getEnabledLayers().test( aLayer );
  88. }
  89. LSET PCB_LAYER_BOX_SELECTOR::getEnabledLayers() const
  90. {
  91. static LSET footprintEditorLayers = LSET::AllLayersMask() & ~LSET::ForbiddenFootprintLayers();
  92. if( m_boardFrame )
  93. return m_boardFrame->GetBoard()->GetEnabledLayers();
  94. else
  95. return footprintEditorLayers;
  96. }
  97. // Returns a color index from the layer id
  98. COLOR4D PCB_LAYER_BOX_SELECTOR::getLayerColor( int aLayer ) const
  99. {
  100. if( m_boardFrame )
  101. {
  102. return m_boardFrame->GetColorSettings()->GetColor( aLayer );
  103. }
  104. else
  105. {
  106. SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager();
  107. FOOTPRINT_EDITOR_SETTINGS* settings = mgr.GetAppSettings<FOOTPRINT_EDITOR_SETTINGS>();
  108. COLOR_SETTINGS* current = mgr.GetColorSettings( settings->m_ColorTheme );
  109. return current->GetColor( aLayer );
  110. }
  111. }
  112. // Returns the name of the layer id
  113. wxString PCB_LAYER_BOX_SELECTOR::getLayerName( int aLayer ) const
  114. {
  115. if( m_boardFrame )
  116. return m_boardFrame->GetBoard()->GetLayerName( ToLAYER_ID( aLayer ) );
  117. else
  118. return BOARD::GetStandardLayerName( ToLAYER_ID( aLayer ) );
  119. }