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 <pcb_edit_frame.h>
34 
35 #include <class_board.h>
36 #include <pcb_layer_box_selector.h>
37 #include <tools/pcb_actions.h>
38 
39 // translate aLayer to its hotkey
41 {
42  switch( aLayer )
43  {
44  case F_Cu: return &PCB_ACTIONS::layerTop;
45  case In1_Cu: return &PCB_ACTIONS::layerInner1;
46  case In2_Cu: return &PCB_ACTIONS::layerInner2;
47  case In3_Cu: return &PCB_ACTIONS::layerInner3;
48  case In4_Cu: return &PCB_ACTIONS::layerInner4;
49  case In5_Cu: return &PCB_ACTIONS::layerInner5;
50  case In6_Cu: return &PCB_ACTIONS::layerInner6;
51  case In7_Cu: return &PCB_ACTIONS::layerInner7;
52  case In8_Cu: return &PCB_ACTIONS::layerInner8;
53  case In9_Cu: return &PCB_ACTIONS::layerInner9;
54  case In10_Cu: return &PCB_ACTIONS::layerInner10;
55  case In11_Cu: return &PCB_ACTIONS::layerInner11;
56  case In12_Cu: return &PCB_ACTIONS::layerInner12;
57  case In13_Cu: return &PCB_ACTIONS::layerInner13;
58  case In14_Cu: return &PCB_ACTIONS::layerInner14;
59  case In15_Cu: return &PCB_ACTIONS::layerInner15;
60  case In16_Cu: return &PCB_ACTIONS::layerInner16;
61  case In17_Cu: return &PCB_ACTIONS::layerInner17;
62  case In18_Cu: return &PCB_ACTIONS::layerInner18;
63  case In19_Cu: return &PCB_ACTIONS::layerInner19;
64  case In20_Cu: return &PCB_ACTIONS::layerInner20;
65  case In21_Cu: return &PCB_ACTIONS::layerInner21;
66  case In22_Cu: return &PCB_ACTIONS::layerInner22;
67  case In23_Cu: return &PCB_ACTIONS::layerInner23;
68  case In24_Cu: return &PCB_ACTIONS::layerInner24;
69  case In25_Cu: return &PCB_ACTIONS::layerInner25;
70  case In26_Cu: return &PCB_ACTIONS::layerInner26;
71  case In27_Cu: return &PCB_ACTIONS::layerInner27;
72  case In28_Cu: return &PCB_ACTIONS::layerInner28;
73  case In29_Cu: return &PCB_ACTIONS::layerInner29;
74  case In30_Cu: return &PCB_ACTIONS::layerInner30;
75  case B_Cu: return &PCB_ACTIONS::layerBottom;
76  default: return nullptr;
77  }
78 }
79 
80 
81 // class to display a layer list in a wxBitmapComboBox.
82 
83 // Reload the Layers
85 {
86  Clear();
87 
88  // Tray to fix a minimum width fot the BitmapComboBox
89  int minwidth = 80;
90 
91  wxClientDC dc( GetParent() ); // The DC for "this" is not always initialized
92 
93  const int BM_SIZE = 14;
94 
96  LSET activated = getEnabledLayers() & ~m_layerMaskDisable;
97  wxString layerstatus;
98 
99  for( LSEQ seq = show.UIOrder(); seq; ++seq )
100  {
101  PCB_LAYER_ID layerid = *seq;
102 
103  if( !m_showNotEnabledBrdlayers && !activated[layerid] )
104  continue;
105  else if( !activated[layerid] )
106  layerstatus = wxT( " " ) + _( "(not activated)" );
107  else
108  layerstatus.Empty();
109 
110  wxBitmap bmp( BM_SIZE, BM_SIZE );
112 
113  wxString layername = getLayerName( layerid ) + layerstatus;
114 
115  if( m_layerhotkeys )
116  {
117  TOOL_ACTION* action = layer2action( layerid );
118 
119  if( action )
120  layername = AddHotkeyName( layername, action->GetHotKey(), IS_COMMENT );
121  }
122 
123  Append( layername, bmp, (void*)(intptr_t) layerid );
124 
125  int w, h;
126  dc.GetTextExtent ( layername, &w, &h );
127  minwidth = std::max( minwidth, w );
128  }
129 
130  if( !m_undefinedLayerName.IsEmpty() )
131  {
132  Append( m_undefinedLayerName, wxNullBitmap, (void*)(intptr_t)UNDEFINED_LAYER );
133 
134  int w, h;
135  dc.GetTextExtent ( m_undefinedLayerName, &w, &h );
136  minwidth = std::max( minwidth, w );
137  }
138 
139  // Approximate bitmap size and margins
140  minwidth += BM_SIZE + 32 + ConvertDialogToPixels( wxSize( 8, 0 ) ).x;
141  SetMinSize( wxSize( minwidth, -1 ) );
142 }
143 
144 
145 // Returns true if the layer id is enabled (i.e. is it should be displayed)
147 {
148  BOARD* board = m_boardFrame->GetBoard();
149 
150  return board->IsLayerEnabled( ToLAYER_ID( aLayer ) );
151 }
152 
153 
155 {
156  BOARD* board = m_boardFrame->GetBoard();
157 
158  return board->GetEnabledLayers();
159 }
160 
161 
162 // Returns a color index from the layer id
164 {
165  wxASSERT( m_boardFrame );
166 
167  return m_boardFrame->GetColorSettings()->GetColor( aLayer );
168 }
169 
170 
171 // Returns the name of the layer id
173 {
174  BOARD* board = m_boardFrame->GetBoard();
175 
176  return board->GetLayerName( ToLAYER_ID( aLayer ) );
177 }
static TOOL_ACTION layerBottom
Definition: pcb_actions.h:282
static TOOL_ACTION layerInner26
Definition: pcb_actions.h:277
static TOOL_ACTION layerInner2
Definition: pcb_actions.h:253
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Return the name of a aLayer.
static TOOL_ACTION layerInner5
Definition: pcb_actions.h:256
static TOOL_ACTION layerInner6
Definition: pcb_actions.h:257
static TOOL_ACTION layerInner7
Definition: pcb_actions.h:258
static TOOL_ACTION layerInner8
Definition: pcb_actions.h:259
static TOOL_ACTION layerInner21
Definition: pcb_actions.h:272
virtual COLOR_SETTINGS * GetColorSettings() override
Helper to retrieve the current color settings.
static TOOL_ACTION * layer2action(PCB_LAYER_ID aLayer)
wxString AddHotkeyName(const wxString &aText, int aHotKey, HOTKEY_ACTION_TYPE aStyle)
AddHotkeyName.
LSET GetEnabledLayers() const
A proxy function that calls the corresponding function in m_BoardSettings Returns a bit-mask of all t...
bool isLayerEnabled(LAYER_NUM aLayer) const override
bool IsLayerEnabled(PCB_LAYER_ID aLayer) const
A proxy function that calls the correspondent function in m_BoardSettings tests whether a given layer...
Definition: class_board.h:480
static TOOL_ACTION layerInner3
Definition: pcb_actions.h:254
static TOOL_ACTION layerInner24
Definition: pcb_actions.h:275
static TOOL_ACTION layerInner11
Definition: pcb_actions.h:262
static TOOL_ACTION layerTop
Definition: pcb_actions.h:251
COLOR4D getLayerColor(LAYER_NUM aLayer) const override
static TOOL_ACTION layerInner23
Definition: pcb_actions.h:274
PCB_LAYER_ID
A quick note on layer IDs:
LSET is a set of PCB_LAYER_IDs.
static TOOL_ACTION layerInner13
Definition: pcb_actions.h:264
static TOOL_ACTION layerInner25
Definition: pcb_actions.h:276
static TOOL_ACTION layerInner18
Definition: pcb_actions.h:269
wxString getLayerName(LAYER_NUM aLayer) const override
static TOOL_ACTION layerInner30
Definition: pcb_actions.h:281
static TOOL_ACTION layerInner29
Definition: pcb_actions.h:280
static TOOL_ACTION layerInner10
Definition: pcb_actions.h:261
static LSET AllLayersMask()
Definition: lset.cpp:786
static TOOL_ACTION layerInner15
Definition: pcb_actions.h:266
static TOOL_ACTION layerInner28
Definition: pcb_actions.h:279
LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
static TOOL_ACTION layerInner27
Definition: pcb_actions.h:278
int LAYER_NUM
This can be replaced with int and removed.
static TOOL_ACTION layerInner17
Definition: pcb_actions.h:268
static void DrawColorSwatch(wxBitmap &aLayerbmp, COLOR4D aBackground, COLOR4D aColor)
static TOOL_ACTION layerInner20
Definition: pcb_actions.h:271
#define BM_SIZE
COLOR4D GetColor(int aLayer) const
static TOOL_ACTION layerInner22
Definition: pcb_actions.h:273
Board layer functions and definitions.
Information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:186
#define _(s)
Definition: 3d_actions.cpp:33
static TOOL_ACTION layerInner14
Definition: pcb_actions.h:265
Represents a single user action.
Definition: tool_action.h:44
static TOOL_ACTION layerInner9
Definition: pcb_actions.h:260
static TOOL_ACTION layerInner16
Definition: pcb_actions.h:267
static TOOL_ACTION layerInner4
Definition: pcb_actions.h:255
BOARD * GetBoard() const
static TOOL_ACTION layerInner19
Definition: pcb_actions.h:270
LSEQ UIOrder() const
Definition: lset.cpp:887
static TOOL_ACTION layerInner1
Definition: pcb_actions.h:252
int GetHotKey() const
Returns the hotkey keycode which initiates the action.
Definition: tool_action.h:85
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:897
static TOOL_ACTION layerInner12
Definition: pcb_actions.h:263
COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:100