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