KiCad PCB EDA Suite
class_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-2015 KiCad Developers, see change_log.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 <wxPcbStruct.h>
35 #include <colors_selection.h>
37 
38 #include <class_board.h>
39 #include <hotkeys.h>
40 
42 
43 // translate aLayer to its hotkey
44 static int layer2hotkey_id( PCB_LAYER_ID aLayer )
45 {
46  switch( aLayer )
47  {
49 
50  case B_Cu: return HK_SWITCH_LAYER_TO_COPPER;
51 
52  case In1_Cu: return HK_SWITCH_LAYER_TO_INNER1;
53  case In2_Cu: return HK_SWITCH_LAYER_TO_INNER2;
54  case In3_Cu: return HK_SWITCH_LAYER_TO_INNER3;
55  case In4_Cu: return HK_SWITCH_LAYER_TO_INNER4;
56  case In5_Cu: return HK_SWITCH_LAYER_TO_INNER5;
57  case In6_Cu: return HK_SWITCH_LAYER_TO_INNER6;
58  case In7_Cu: return HK_SWITCH_LAYER_TO_INNER7;
59  case In8_Cu: return HK_SWITCH_LAYER_TO_INNER8;
60  case In9_Cu: return HK_SWITCH_LAYER_TO_INNER9;
66 
67  default:
68  return -1;
69  }
70 }
71 
72 
73 // class to display a layer list in a wxBitmapComboBox.
74 
75 // Reload the Layers
77 {
78  Clear();
79 
80  // Tray to fix a minimum width fot the BitmapComboBox
81  int minwidth = 80;
82 
83  wxClientDC dc( GetParent() ); // The DC for "this" is not always initialized
84 
85  const int BM_SIZE = 14;
86 
88  LSET activated = getEnabledLayers() & ~m_layerMaskDisable;
89  wxString layerstatus;
90 
91  for( LSEQ seq = show.UIOrder(); seq; ++seq )
92  {
93  PCB_LAYER_ID layerid = *seq;
94 
95  if( !m_showNotEnabledBrdlayers && !activated[layerid] )
96  continue;
97  else if( !activated[layerid] )
98  layerstatus = wxT( " " ) + _( "(not activated)" );
99  else
100  layerstatus.Empty();
101 
102  wxBitmap layerbmp( BM_SIZE, BM_SIZE );
103  SetBitmapLayer( layerbmp, layerid );
104 
105  wxString layername = GetLayerName( layerid ) + layerstatus;
106 
107  if( m_layerhotkeys && m_hotkeys )
108  {
109  int id = layer2hotkey_id( layerid );
110 
111  if( id != -1 )
112  layername = AddHotkeyName( layername, m_hotkeys, id, IS_COMMENT );
113  }
114 
115  Append( layername, layerbmp, (void*)(intptr_t) layerid );
116 
117  int w, h;
118  dc.GetTextExtent ( layername, &w, &h );
119  minwidth = std::max( minwidth, w );
120  }
121 
122  minwidth += BM_SIZE + 35; // Take in account the bitmap size and margins
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  BOARD* board = m_boardFrame->GetBoard();
153  wxASSERT( board );
154 
155  return board->GetLayerColor( ToLAYER_ID( aLayer ) );
156 }
157 
158 
159 // Returns the name of the layer id
161 {
162  wxASSERT( m_boardFrame );
163  BOARD* board = m_boardFrame->GetBoard();
164  wxASSERT( board );
165 
166  return board->GetLayerName( ToLAYER_ID( aLayer ) );
167 }
168 
COLOR4D GetLayerColor(PCB_LAYER_ID aLayer) const
Function GetLayerColor gets a layer color for any valid layer, including non-copper ones...
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:431
BOARD * GetBoard() const
LSET GetEnabledLayers() const
Function GetEnabledLayers is a proxy function that calls the corresponding function in m_BoardSetting...
void SetBitmapLayer(wxBitmap &aLayerbmp, LAYER_NUM aLayer)
Pcbnew hotkeys.
static int layer2hotkey_id(PCB_LAYER_ID aLayer)
PCB_LAYER_ID
A quick note on layer IDs:
Class LSET is a set of PCB_LAYER_IDs.
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:676
Class LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
int LAYER_NUM
Type LAYER_NUM can be replaced with int and removed.
#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:169
The common library.
COLOR4D GetLayerColor(LAYER_NUM aLayer) const override
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:767
wxString GetLayerName(LAYER_NUM aLayer) const override
LSEQ UIOrder() const
Definition: lset.cpp:752
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39