KiCad PCB EDA Suite
pcb_layer_box_selector.cpp
Go to the documentation of this file.
1 
7 /*
8  * This program source code file is part of KiCad, a free EDA CAD application.
9  *
10  * Copyright (C) 1992-2015 Jean-Pierre Charras <jean-pierre.charras@ujf-grenoble.fr>
11  * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
12  * Copyright (C) 1992-2018 KiCad Developers, see AUTHORS.txt for contributors.
13  *
14  * This program is free software; you can redistribute it and/or
15  * modify it under the terms of the GNU General Public License
16  * as published by the Free Software Foundation; either version 2
17  * of the License, or (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  * GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with this program; if not, you may find one here:
26  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
27  * or you may search the http://www.gnu.org website for the version 2 license,
28  * or you may write to the Free Software Foundation, Inc.,
29  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
30  */
31 #include <common.h>
32 #include <pcbnew.h>
33 #include <pcb_edit_frame.h>
34 #include <board_design_settings.h>
36 
37 #include <class_board.h>
38 #include <hotkeys.h>
39 
40 #include <pcb_layer_box_selector.h>
41 
42 // translate aLayer to its hotkey
43 static int layer2hotkey_id( PCB_LAYER_ID aLayer )
44 {
45  switch( aLayer )
46  {
48 
49  case B_Cu: return HK_SWITCH_LAYER_TO_COPPER;
50 
51  case In1_Cu: return HK_SWITCH_LAYER_TO_INNER1;
52  case In2_Cu: return HK_SWITCH_LAYER_TO_INNER2;
53  case In3_Cu: return HK_SWITCH_LAYER_TO_INNER3;
54  case In4_Cu: return HK_SWITCH_LAYER_TO_INNER4;
55  case In5_Cu: return HK_SWITCH_LAYER_TO_INNER5;
56  case In6_Cu: return HK_SWITCH_LAYER_TO_INNER6;
57  case In7_Cu: return HK_SWITCH_LAYER_TO_INNER7;
58  case In8_Cu: return HK_SWITCH_LAYER_TO_INNER8;
59  case In9_Cu: return HK_SWITCH_LAYER_TO_INNER9;
65 
66  default:
67  return -1;
68  }
69 }
70 
71 
72 // class to display a layer list in a wxBitmapComboBox.
73 
74 // Reload the Layers
76 {
77  Clear();
78 
79  // Tray to fix a minimum width fot the BitmapComboBox
80  int minwidth = 80;
81 
82  wxClientDC dc( GetParent() ); // The DC for "this" is not always initialized
83 
84  const int BM_SIZE = 14;
85 
87  LSET activated = getEnabledLayers() & ~m_layerMaskDisable;
88  wxString layerstatus;
89 
90  for( LSEQ seq = show.UIOrder(); seq; ++seq )
91  {
92  PCB_LAYER_ID layerid = *seq;
93 
94  if( !m_showNotEnabledBrdlayers && !activated[layerid] )
95  continue;
96  else if( !activated[layerid] )
97  layerstatus = wxT( " " ) + _( "(not activated)" );
98  else
99  layerstatus.Empty();
100 
101  wxBitmap bmp( BM_SIZE, BM_SIZE );
103 
104  wxString layername = GetLayerName( layerid ) + layerstatus;
105 
106  if( m_layerhotkeys && m_hotkeys )
107  {
108  int id = layer2hotkey_id( layerid );
109 
110  if( id != -1 )
111  layername = AddHotkeyName( layername, m_hotkeys, id, IS_COMMENT );
112  }
113 
114  Append( layername, bmp, (void*)(intptr_t) layerid );
115 
116  int w, h;
117  dc.GetTextExtent ( layername, &w, &h );
118  minwidth = std::max( minwidth, w );
119  }
120 
121  // Approximate bitmap size and margins
122  minwidth += BM_SIZE + 32 + ConvertDialogToPixels( wxSize( 8, 0 ) ).x;
123  SetMinSize( wxSize( minwidth, -1 ) );
124 }
125 
126 
127 // Returns true if the layer id is enabled (i.e. is it should be displayed)
129 {
130  wxASSERT( m_boardFrame != NULL );
131  BOARD* board = m_boardFrame->GetBoard();
132  wxASSERT( board != NULL );
133 
134  return board->IsLayerEnabled( ToLAYER_ID( aLayer ) );
135 }
136 
137 
139 {
140  wxASSERT( m_boardFrame != NULL );
141  BOARD* board = m_boardFrame->GetBoard();
142  wxASSERT( board != NULL );
143 
144  return board->GetEnabledLayers();
145 }
146 
147 
148 // Returns a color index from the layer id
150 {
151  wxASSERT( m_boardFrame );
152 
153  return m_boardFrame->Settings().Colors().GetLayerColor( aLayer );
154 }
155 
156 
157 // Returns the name of the layer id
159 {
160  wxASSERT( m_boardFrame );
161  BOARD* board = m_boardFrame->GetBoard();
162  wxASSERT( board );
163 
164  return board->GetLayerName( ToLAYER_ID( aLayer ) );
165 }
EDA_HOTKEY_CONFIG * m_hotkeys
Class BOARD to handle a board.
bool IsLayerEnabled(PCB_LAYER_ID aLayer) const
Function IsLayerEnabled is a proxy function that calls the correspondent function in m_BoardSettings ...
Definition: class_board.h:445
BOARD * GetBoard() const
LSET GetEnabledLayers() const
Function GetEnabledLayers is a proxy function that calls the corresponding function in m_BoardSetting...
Pcbnew hotkeys.
PCB_LAYER_ID
A quick note on layer IDs:
Class LSET is a set of PCB_LAYER_IDs.
PCB_GENERAL_SETTINGS & Settings()
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Function GetLayerName returns the name of a layer given by aLayer.
bool IsLayerEnabled(LAYER_NUM aLayer) const override
static LSET AllLayersMask()
Definition: lset.cpp:710
Class LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
static int layer2hotkey_id(PCB_LAYER_ID aLayer)
COLORS_DESIGN_SETTINGS & Colors()
int LAYER_NUM
Type LAYER_NUM can be replaced with int and removed.
static void DrawColorSwatch(wxBitmap &aLayerbmp, COLOR4D aBackground, COLOR4D aColor)
#define BM_SIZE
wxString AddHotkeyName(const wxString &aText, EDA_HOTKEY **aList, int aCommandId, HOTKEY_ACTION_TYPE aShortCutType)
Function AddHotkeyName Add the key name from the Command id value ( m_Idcommand member value) ...
Board layer functions and definitions.
#define max(a, b)
Definition: auxiliary.h:86
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:170
The common library.
COLOR4D GetLayerColor(LAYER_NUM aLayer) const
Function GetLayerColor.
COLOR4D GetLayerColor(LAYER_NUM aLayer) const override
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:810
wxString GetLayerName(LAYER_NUM aLayer) const override
LSEQ UIOrder() const
Definition: lset.cpp:800
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39