KiCad PCB EDA Suite
pcb_layer_box_selector.cpp
Go to the documentation of this file.
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 (C) 1992-2021 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_edit_frame.h>
26 #include <layer_ids.h>
28 
29 #include <board.h>
30 #include <pcb_layer_box_selector.h>
31 #include <tools/pcb_actions.h>
32 
33 // translate aLayer to its action
35 {
36  switch( aLayer )
37  {
38  case F_Cu: return &PCB_ACTIONS::layerTop;
39  case In1_Cu: return &PCB_ACTIONS::layerInner1;
40  case In2_Cu: return &PCB_ACTIONS::layerInner2;
41  case In3_Cu: return &PCB_ACTIONS::layerInner3;
42  case In4_Cu: return &PCB_ACTIONS::layerInner4;
43  case In5_Cu: return &PCB_ACTIONS::layerInner5;
44  case In6_Cu: return &PCB_ACTIONS::layerInner6;
45  case In7_Cu: return &PCB_ACTIONS::layerInner7;
46  case In8_Cu: return &PCB_ACTIONS::layerInner8;
47  case In9_Cu: return &PCB_ACTIONS::layerInner9;
48  case In10_Cu: return &PCB_ACTIONS::layerInner10;
49  case In11_Cu: return &PCB_ACTIONS::layerInner11;
50  case In12_Cu: return &PCB_ACTIONS::layerInner12;
51  case In13_Cu: return &PCB_ACTIONS::layerInner13;
52  case In14_Cu: return &PCB_ACTIONS::layerInner14;
53  case In15_Cu: return &PCB_ACTIONS::layerInner15;
54  case In16_Cu: return &PCB_ACTIONS::layerInner16;
55  case In17_Cu: return &PCB_ACTIONS::layerInner17;
56  case In18_Cu: return &PCB_ACTIONS::layerInner18;
57  case In19_Cu: return &PCB_ACTIONS::layerInner19;
58  case In20_Cu: return &PCB_ACTIONS::layerInner20;
59  case In21_Cu: return &PCB_ACTIONS::layerInner21;
60  case In22_Cu: return &PCB_ACTIONS::layerInner22;
61  case In23_Cu: return &PCB_ACTIONS::layerInner23;
62  case In24_Cu: return &PCB_ACTIONS::layerInner24;
63  case In25_Cu: return &PCB_ACTIONS::layerInner25;
64  case In26_Cu: return &PCB_ACTIONS::layerInner26;
65  case In27_Cu: return &PCB_ACTIONS::layerInner27;
66  case In28_Cu: return &PCB_ACTIONS::layerInner28;
67  case In29_Cu: return &PCB_ACTIONS::layerInner29;
68  case In30_Cu: return &PCB_ACTIONS::layerInner30;
69  case B_Cu: return &PCB_ACTIONS::layerBottom;
70  default: return nullptr;
71  }
72 }
73 
74 
75 // class to display a layer list in a wxBitmapComboBox.
76 
77 // Reload the Layers
79 {
80  Freeze();
81  Clear();
82 
83  const int BM_SIZE = 14;
84 
86  LSET activated = getEnabledLayers() & ~m_layerMaskDisable;
87  wxString layerstatus;
88 
89  for( PCB_LAYER_ID layerid : show.UIOrder() )
90  {
91  if( !m_showNotEnabledBrdlayers && !activated[layerid] )
92  continue;
93  else if( !activated[layerid] )
94  layerstatus = wxT( " " ) + _( "(not activated)" );
95  else
96  layerstatus.Empty();
97 
98  wxBitmap bmp( BM_SIZE, BM_SIZE );
100 
101  wxString layername = getLayerName( layerid ) + layerstatus;
102 
103  if( m_layerhotkeys )
104  {
105  TOOL_ACTION* action = layer2action( layerid );
106 
107  if( action )
108  layername = AddHotkeyName( layername, action->GetHotKey(), IS_COMMENT );
109  }
110 
111  Append( layername, bmp, (void*)(intptr_t) layerid );
112  }
113 
114  if( !m_undefinedLayerName.IsEmpty() )
115  Append( m_undefinedLayerName, wxNullBitmap, (void*)(intptr_t)UNDEFINED_LAYER );
116 
117  // Ensure the size of the widget is enough to show the text and the icon
118  // We have to have a selected item when doing this, because otherwise GTK
119  // will just choose a random size that might not fit the actual data
120  // (such as in cases where the font size is very large). So we select
121  // the first item, get the size of the control and make that the minimum size,
122  // then remove the selection (which was the initial state).
123  SetSelection( 0 );
124 
125  SetMinSize( wxSize( -1, -1 ) );
126  wxSize bestSize = GetBestSize();
127 
128  bestSize.x = GetBestSize().x + BM_SIZE + 10;
129  SetMinSize( bestSize );
130 
131  SetSelection( wxNOT_FOUND );
132  Thaw();
133 }
134 
135 
136 // Returns true if the layer id is enabled (i.e. is it should be displayed)
138 {
139  BOARD* board = m_boardFrame->GetBoard();
140 
141  return board->IsLayerEnabled( ToLAYER_ID( aLayer ) );
142 }
143 
144 
146 {
147  BOARD* board = m_boardFrame->GetBoard();
148 
149  return board->GetEnabledLayers();
150 }
151 
152 
153 // Returns a color index from the layer id
155 {
156  wxASSERT( m_boardFrame );
157 
158  return m_boardFrame->GetColorSettings()->GetColor( aLayer );
159 }
160 
161 
162 // Returns the name of the layer id
164 {
165  BOARD* board = m_boardFrame->GetBoard();
166 
167  return board->GetLayerName( ToLAYER_ID( aLayer ) );
168 }
static TOOL_ACTION layerBottom
Definition: pcb_actions.h:284
static TOOL_ACTION layerInner26
Definition: pcb_actions.h:279
static void DrawColorSwatch(wxBitmap &aLayerbmp, const COLOR4D &aBackground, const COLOR4D &aColor)
static TOOL_ACTION layerInner2
Definition: pcb_actions.h:255
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Return the name of a aLayer.
Definition: board.cpp:362
static TOOL_ACTION layerInner5
Definition: pcb_actions.h:258
static TOOL_ACTION layerInner6
Definition: pcb_actions.h:259
static TOOL_ACTION layerInner7
Definition: pcb_actions.h:260
static TOOL_ACTION layerInner8
Definition: pcb_actions.h:261
static TOOL_ACTION layerInner21
Definition: pcb_actions.h:274
static TOOL_ACTION * layer2action(PCB_LAYER_ID aLayer)
wxString AddHotkeyName(const wxString &aText, int aHotKey, HOTKEY_ACTION_TYPE aStyle)
int LAYER_NUM
This can be replaced with int and removed.
Definition: layer_ids.h:41
LSET GetEnabledLayers() const
A proxy function that calls the corresponding function in m_BoardSettings.
Definition: board.cpp:467
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: board.cpp:493
static TOOL_ACTION layerInner3
Definition: pcb_actions.h:256
static TOOL_ACTION layerInner24
Definition: pcb_actions.h:277
static TOOL_ACTION layerInner11
Definition: pcb_actions.h:264
static TOOL_ACTION layerTop
Definition: pcb_actions.h:253
COLOR4D getLayerColor(LAYER_NUM aLayer) const override
virtual COLOR_SETTINGS * GetColorSettings() const override
Helper to retrieve the current color settings.
static TOOL_ACTION layerInner23
Definition: pcb_actions.h:276
LSET is a set of PCB_LAYER_IDs.
Definition: layer_ids.h:504
static TOOL_ACTION layerInner13
Definition: pcb_actions.h:266
static TOOL_ACTION layerInner25
Definition: pcb_actions.h:278
static TOOL_ACTION layerInner18
Definition: pcb_actions.h:271
wxString getLayerName(LAYER_NUM aLayer) const override
static TOOL_ACTION layerInner30
Definition: pcb_actions.h:283
static TOOL_ACTION layerInner29
Definition: pcb_actions.h:282
#define _(s)
static TOOL_ACTION layerInner10
Definition: pcb_actions.h:263
static LSET AllLayersMask()
Definition: lset.cpp:787
static TOOL_ACTION layerInner15
Definition: pcb_actions.h:268
static TOOL_ACTION layerInner28
Definition: pcb_actions.h:281
static TOOL_ACTION layerInner27
Definition: pcb_actions.h:280
static TOOL_ACTION layerInner17
Definition: pcb_actions.h:270
static TOOL_ACTION layerInner20
Definition: pcb_actions.h:273
#define BM_SIZE
COLOR4D GetColor(int aLayer) const
static TOOL_ACTION layerInner22
Definition: pcb_actions.h:275
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:190
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:65
Definition: layer_ids.h:71
static TOOL_ACTION layerInner14
Definition: pcb_actions.h:267
Represent a single user action.
Definition: tool_action.h:67
static TOOL_ACTION layerInner9
Definition: pcb_actions.h:262
static TOOL_ACTION layerInner16
Definition: pcb_actions.h:269
PCB background color.
Definition: layer_ids.h:216
static TOOL_ACTION layerInner4
Definition: pcb_actions.h:257
BOARD * GetBoard() const
static TOOL_ACTION layerInner19
Definition: pcb_actions.h:272
LSEQ UIOrder() const
Definition: lset.cpp:895
static TOOL_ACTION layerInner1
Definition: pcb_actions.h:254
int GetHotKey() const
Return the hotkey keycode which initiates the action.
Definition: tool_action.h:111
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:905
static TOOL_ACTION layerInner12
Definition: pcb_actions.h:265
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:103