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>
36 
37 #include <class_board.h>
38 #include <hotkeys.h>
39 
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 layerbmp( BM_SIZE, BM_SIZE );
102  SetBitmapLayer( layerbmp, layerid );
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, layerbmp, (void*)(intptr_t) layerid );
115 
116  int w, h;
117  dc.GetTextExtent ( layername, &w, &h );
118  minwidth = std::max( minwidth, w );
119  }
120 
121  minwidth += BM_SIZE + 35; // Take in account the bitmap size and margins
122  SetMinSize( wxSize( minwidth, -1 ) );
123 }
124 
125 
126 // Returns true if the layer id is enabled (i.e. is it should be displayed)
128 {
129  wxASSERT( m_boardFrame != NULL );
130  BOARD* board = m_boardFrame->GetBoard();
131  wxASSERT( board != NULL );
132 
133  return board->IsLayerEnabled( ToLAYER_ID( aLayer ) );
134 }
135 
136 
138 {
139  wxASSERT( m_boardFrame != NULL );
140  BOARD* board = m_boardFrame->GetBoard();
141  wxASSERT( board != NULL );
142 
143  return board->GetEnabledLayers();
144 }
145 
146 
147 // Returns a color index from the layer id
149 {
150  wxASSERT( m_boardFrame );
151 
152  return m_boardFrame->Settings().Colors().GetLayerColor( ToLAYER_ID( aLayer ) );
153 }
154 
155 
156 // Returns the name of the layer id
158 {
159  wxASSERT( m_boardFrame );
160  BOARD* board = m_boardFrame->GetBoard();
161  wxASSERT( board );
162 
163  return board->GetLayerName( ToLAYER_ID( aLayer ) );
164 }
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.
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:676
Class LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
COLORS_DESIGN_SETTINGS & Colors()
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
Function GetLayerColor.
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