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.

140 lines
4.7 KiB

11 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 The 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 "pcb_layer_box_selector.h"
  26. #include <board.h>
  27. #include <layer_ids.h>
  28. #include <pcb_edit_frame.h>
  29. #include <pcb_layer_presentation.h>
  30. #include <settings/color_settings.h>
  31. #include <tools/pcb_actions.h>
  32. #include <dpi_scaling_common.h>
  33. #include <wx/wupdlock.h>
  34. PCB_LAYER_BOX_SELECTOR::PCB_LAYER_BOX_SELECTOR( wxWindow* parent, wxWindowID id, const wxString& value,
  35. const wxPoint& pos, const wxSize& size, int n,
  36. const wxString choices[], int style ) :
  37. LAYER_BOX_SELECTOR( parent, id, pos, size, n, choices ),
  38. m_boardFrame( nullptr ),
  39. m_showNotEnabledBrdlayers( false ),
  40. m_layerPresentation( std::make_unique<PCB_LAYER_PRESENTATION>( nullptr ) ) // The parent isn't always the frame
  41. {
  42. }
  43. void PCB_LAYER_BOX_SELECTOR::SetBoardFrame( PCB_BASE_FRAME* aFrame )
  44. {
  45. m_boardFrame = aFrame;
  46. m_layerPresentation->SetBoardFrame( m_boardFrame );
  47. }
  48. // Reload the Layers
  49. void PCB_LAYER_BOX_SELECTOR::Resync()
  50. {
  51. wxWindowUpdateLocker updateLock( this );
  52. Clear();
  53. const int size = 14;
  54. LSET show = ( LSET::AllCuMask() | LSET::AllNonCuMask() ) & ~m_layerMaskDisable;
  55. LSET activated = getEnabledLayers() & ~m_layerMaskDisable;
  56. wxString layerstatus;
  57. for( PCB_LAYER_ID layerid : show.UIOrder() )
  58. {
  59. if( !m_showNotEnabledBrdlayers && !activated[layerid] )
  60. continue;
  61. else if( !activated[layerid] )
  62. layerstatus = wxT( " " ) + _( "(not activated)" );
  63. else
  64. layerstatus.Empty();
  65. wxVector<wxBitmap> bitmaps;
  66. for( int scale = 1; scale <= 3; scale++ )
  67. {
  68. wxBitmap bmp( size * scale, size * scale );
  69. m_layerPresentation->DrawColorSwatch( bmp, layerid );
  70. bmp.SetScaleFactor( scale );
  71. bitmaps.push_back( bmp );
  72. }
  73. wxString layername = m_layerPresentation->getLayerName( layerid ) + layerstatus;
  74. if( m_layerhotkeys )
  75. {
  76. TOOL_ACTION* action = PCB_ACTIONS::LayerIDToAction( layerid );
  77. if( action )
  78. layername = AddHotkeyName( layername, action->GetHotKey(), IS_COMMENT );
  79. }
  80. Append( layername, wxBitmapBundle::FromBitmaps( bitmaps ), (void*) (intptr_t) layerid );
  81. }
  82. if( !m_undefinedLayerName.IsEmpty() )
  83. Append( m_undefinedLayerName, wxNullBitmap, (void*)(intptr_t)UNDEFINED_LAYER );
  84. // Ensure the size of the widget is enough to show the text and the icon
  85. // We have to have a selected item when doing this, because otherwise GTK
  86. // will just choose a random size that might not fit the actual data
  87. // (such as in cases where the font size is very large). So we select
  88. // the first item, get the size of the control and make that the minimum size,
  89. // then remove the selection (which was the initial state).
  90. SetSelection( 0 );
  91. SetMinSize( wxSize( -1, -1 ) );
  92. wxSize bestSize = GetBestSize();
  93. bestSize.x = GetBestSize().x + size + 10;
  94. SetMinSize( bestSize );
  95. SetSelection( wxNOT_FOUND );
  96. Fit();
  97. }
  98. // Returns true if the layer id is enabled (i.e. is it should be displayed)
  99. bool PCB_LAYER_BOX_SELECTOR::isLayerEnabled( int aLayer ) const
  100. {
  101. return getEnabledLayers().test( aLayer );
  102. }
  103. LSET PCB_LAYER_BOX_SELECTOR::getEnabledLayers() const
  104. {
  105. static const LSET footprintEditorLayers = LSET::AllLayersMask();
  106. if( m_boardFrame )
  107. return m_boardFrame->GetBoard()->GetEnabledLayers();
  108. else
  109. return footprintEditorLayers;
  110. }