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 <pcb_layer_box_selector.h>
39 #include <tools/pcb_actions.h>
40 
41 // translate aLayer to its hotkey
43 {
44  switch( aLayer )
45  {
46  case F_Cu: return &PCB_ACTIONS::layerTop;
47 
48  case B_Cu: return &PCB_ACTIONS::layerBottom;
49 
50  case In1_Cu: return &PCB_ACTIONS::layerInner1;
51  case In2_Cu: return &PCB_ACTIONS::layerInner2;
52  case In3_Cu: return &PCB_ACTIONS::layerInner3;
53  case In4_Cu: return &PCB_ACTIONS::layerInner4;
54  case In5_Cu: return &PCB_ACTIONS::layerInner5;
55  case In6_Cu: return &PCB_ACTIONS::layerInner6;
56 
57  default:
58  return nullptr;
59  }
60 }
61 
62 
63 // class to display a layer list in a wxBitmapComboBox.
64 
65 // Reload the Layers
67 {
68  Clear();
69 
70  // Tray to fix a minimum width fot the BitmapComboBox
71  int minwidth = 80;
72 
73  wxClientDC dc( GetParent() ); // The DC for "this" is not always initialized
74 
75  const int BM_SIZE = 14;
76 
78  LSET activated = getEnabledLayers() & ~m_layerMaskDisable;
79  wxString layerstatus;
80 
81  for( LSEQ seq = show.UIOrder(); seq; ++seq )
82  {
83  PCB_LAYER_ID layerid = *seq;
84 
85  if( !m_showNotEnabledBrdlayers && !activated[layerid] )
86  continue;
87  else if( !activated[layerid] )
88  layerstatus = wxT( " " ) + _( "(not activated)" );
89  else
90  layerstatus.Empty();
91 
92  wxBitmap bmp( BM_SIZE, BM_SIZE );
94 
95  wxString layername = GetLayerName( layerid ) + layerstatus;
96 
97  if( m_layerhotkeys )
98  {
99  TOOL_ACTION* action = layer2action( layerid );
100 
101  if( action )
102  layername = AddHotkeyName( layername, action->GetHotKey(), IS_COMMENT );
103  }
104 
105  Append( layername, bmp, (void*)(intptr_t) layerid );
106 
107  int w, h;
108  dc.GetTextExtent ( layername, &w, &h );
109  minwidth = std::max( minwidth, w );
110  }
111 
112  // Approximate bitmap size and margins
113  minwidth += BM_SIZE + 32 + ConvertDialogToPixels( wxSize( 8, 0 ) ).x;
114  SetMinSize( wxSize( minwidth, -1 ) );
115 }
116 
117 
118 // Returns true if the layer id is enabled (i.e. is it should be displayed)
120 {
121  wxASSERT( m_boardFrame != NULL );
122  BOARD* board = m_boardFrame->GetBoard();
123  wxASSERT( board != NULL );
124 
125  return board->IsLayerEnabled( ToLAYER_ID( aLayer ) );
126 }
127 
128 
130 {
131  wxASSERT( m_boardFrame != NULL );
132  BOARD* board = m_boardFrame->GetBoard();
133  wxASSERT( board != NULL );
134 
135  return board->GetEnabledLayers();
136 }
137 
138 
139 // Returns a color index from the layer id
141 {
142  wxASSERT( m_boardFrame );
143 
144  return m_boardFrame->Settings().Colors().GetLayerColor( aLayer );
145 }
146 
147 
148 // Returns the name of the layer id
150 {
151  wxASSERT( m_boardFrame );
152  BOARD* board = m_boardFrame->GetBoard();
153  wxASSERT( board );
154 
155  return board->GetLayerName( ToLAYER_ID( aLayer ) );
156 }
static TOOL_ACTION layerBottom
Definition: pcb_actions.h:269
static TOOL_ACTION layerInner2
Definition: pcb_actions.h:240
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Function GetLayerName returns the name of a layer given by aLayer.
static TOOL_ACTION layerInner5
Definition: pcb_actions.h:243
static TOOL_ACTION layerInner6
Definition: pcb_actions.h:244
static TOOL_ACTION * layer2action(PCB_LAYER_ID aLayer)
wxString AddHotkeyName(const wxString &aText, int aHotKey, HOTKEY_ACTION_TYPE aStyle)
AddHotkeyName.
LSET GetEnabledLayers() const
Function GetEnabledLayers is a proxy function that calls the corresponding function in m_BoardSetting...
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:447
static TOOL_ACTION layerInner3
Definition: pcb_actions.h:241
static TOOL_ACTION layerTop
Definition: pcb_actions.h:238
COLOR4D GetLayerColor(LAYER_NUM aLayer) const
Function GetLayerColor.
PCB_LAYER_ID
A quick note on layer IDs:
Class LSET is a set of PCB_LAYER_IDs.
PCB_GENERAL_SETTINGS & Settings()
bool IsLayerEnabled(LAYER_NUM aLayer) const override
static LSET AllLayersMask()
Definition: lset.cpp:713
#define _(s)
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.
static void DrawColorSwatch(wxBitmap &aLayerbmp, COLOR4D aBackground, COLOR4D aColor)
#define BM_SIZE
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:161
Class TOOL_ACTION.
Definition: tool_action.h:46
The common library.
COLOR4D GetLayerColor(LAYER_NUM aLayer) const override
static TOOL_ACTION layerInner4
Definition: pcb_actions.h:242
BOARD * GetBoard() const
LSEQ UIOrder() const
Definition: lset.cpp:803
static TOOL_ACTION layerInner1
Definition: pcb_actions.h:239
int GetHotKey() const
Function GetHotKey() Returns the hotkey keycode which initiates the action.
Definition: tool_action.h:90
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:813
wxString GetLayerName(LAYER_NUM aLayer) const override
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39