KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 <[email protected]>
5 * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <[email protected]>
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
26#include <pgm_base.h>
29#include <pcb_edit_frame.h>
30#include <layer_ids.h>
32#include <board.h>
34#include <tools/pcb_actions.h>
35
36
37// translate aLayer to its action
39{
40 switch( aLayer )
41 {
42 case F_Cu: return &PCB_ACTIONS::layerTop;
43 case In1_Cu: return &PCB_ACTIONS::layerInner1;
44 case In2_Cu: return &PCB_ACTIONS::layerInner2;
45 case In3_Cu: return &PCB_ACTIONS::layerInner3;
46 case In4_Cu: return &PCB_ACTIONS::layerInner4;
47 case In5_Cu: return &PCB_ACTIONS::layerInner5;
48 case In6_Cu: return &PCB_ACTIONS::layerInner6;
49 case In7_Cu: return &PCB_ACTIONS::layerInner7;
50 case In8_Cu: return &PCB_ACTIONS::layerInner8;
51 case In9_Cu: return &PCB_ACTIONS::layerInner9;
73 case B_Cu: return &PCB_ACTIONS::layerBottom;
74 default: return nullptr;
75 }
76}
77
78
79// class to display a layer list in a wxBitmapComboBox.
80
81// Reload the Layers
83{
84 Freeze();
85 Clear();
86
87#ifdef __WXMSW__
88 DPI_SCALING dpi( nullptr, this );
89 int size = static_cast<int>( 14 / dpi.GetContentScaleFactor() );
90#else
91 const int size = 14;
92#endif
93
94 LSET show = LSET::AllLayersMask() & ~m_layerMaskDisable;
95 LSET activated = getEnabledLayers() & ~m_layerMaskDisable;
96 wxString layerstatus;
97
98 for( PCB_LAYER_ID layerid : show.UIOrder() )
99 {
100 if( !m_showNotEnabledBrdlayers && !activated[layerid] )
101 continue;
102 else if( !activated[layerid] )
103 layerstatus = wxT( " " ) + _( "(not activated)" );
104 else
105 layerstatus.Empty();
106
107 wxBitmap bmp( size, size );
109
110 wxString layername = getLayerName( layerid ) + layerstatus;
111
112 if( m_layerhotkeys )
113 {
114 TOOL_ACTION* action = layer2action( layerid );
115
116 if( action )
117 layername = AddHotkeyName( layername, action->GetHotKey(), IS_COMMENT );
118 }
119
120 Append( layername, bmp, (void*)(intptr_t) layerid );
121 }
122
123 if( !m_undefinedLayerName.IsEmpty() )
124 Append( m_undefinedLayerName, wxNullBitmap, (void*)(intptr_t)UNDEFINED_LAYER );
125
126 // Ensure the size of the widget is enough to show the text and the icon
127 // We have to have a selected item when doing this, because otherwise GTK
128 // will just choose a random size that might not fit the actual data
129 // (such as in cases where the font size is very large). So we select
130 // the first item, get the size of the control and make that the minimum size,
131 // then remove the selection (which was the initial state).
132 SetSelection( 0 );
133
134 SetMinSize( wxSize( -1, -1 ) );
135 wxSize bestSize = GetBestSize();
136
137 bestSize.x = GetBestSize().x + size + 10;
138 SetMinSize( bestSize );
139
140 SetSelection( wxNOT_FOUND );
141 Thaw();
142}
143
144
145// Returns true if the layer id is enabled (i.e. is it should be displayed)
147{
148 return getEnabledLayers().test( aLayer );
149}
150
151
153{
154 static LSET footprintEditorLayers = LSET::AllLayersMask() & ~LSET::ForbiddenFootprintLayers();
155
156 if( m_boardFrame )
158 else
159 return footprintEditorLayers;
160}
161
162
163// Returns a color index from the layer id
165{
166 if( m_boardFrame )
167 {
168 return m_boardFrame->GetColorSettings()->GetColor( aLayer );
169 }
170 else
171 {
172 SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager();
174 COLOR_SETTINGS* current = mgr.GetColorSettings( settings->m_ColorTheme );
175
176 return current->GetColor( aLayer );
177 }
178}
179
180
181// Returns the name of the layer id
182wxString PCB_LAYER_BOX_SELECTOR::getLayerName( int aLayer ) const
183{
184 if( m_boardFrame )
185 return m_boardFrame->GetBoard()->GetLayerName( ToLAYER_ID( aLayer ) );
186 else
187 return BOARD::GetStandardLayerName( ToLAYER_ID( aLayer ) );
188}
wxString m_ColorTheme
Active color theme name.
Definition: app_settings.h:190
LSET GetEnabledLayers() const
A proxy function that calls the corresponding function in m_BoardSettings.
Definition: board.cpp:611
static wxString GetStandardLayerName(PCB_LAYER_ID aLayerId)
Return an "English Standard" name of a PCB layer when given aLayerNumber.
Definition: board.h:731
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Return the name of a aLayer.
Definition: board.cpp:498
Color settings are a bit different than most of the settings objects in that there can be more than o...
COLOR4D GetColor(int aLayer) const
Class to handle configuration and automatic determination of the DPI scale to use for canvases.
Definition: dpi_scaling.h:37
double GetContentScaleFactor() const
Get the content scale factor, which may be different from the scale factor on some platforms.
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:103
static void DrawColorSwatch(wxBitmap &aLayerbmp, const COLOR4D &aBackground, const COLOR4D &aColor)
LSET is a set of PCB_LAYER_IDs.
Definition: layer_ids.h:536
LSEQ UIOrder() const
Definition: lset.cpp:922
static LSET AllLayersMask()
Definition: lset.cpp:808
static TOOL_ACTION layerInner12
Definition: pcb_actions.h:302
static TOOL_ACTION layerInner8
Definition: pcb_actions.h:298
static TOOL_ACTION layerInner3
Definition: pcb_actions.h:293
static TOOL_ACTION layerInner2
Definition: pcb_actions.h:292
static TOOL_ACTION layerInner25
Definition: pcb_actions.h:315
static TOOL_ACTION layerInner24
Definition: pcb_actions.h:314
static TOOL_ACTION layerInner29
Definition: pcb_actions.h:319
static TOOL_ACTION layerInner11
Definition: pcb_actions.h:301
static TOOL_ACTION layerInner16
Definition: pcb_actions.h:306
static TOOL_ACTION layerInner26
Definition: pcb_actions.h:316
static TOOL_ACTION layerInner18
Definition: pcb_actions.h:308
static TOOL_ACTION layerInner14
Definition: pcb_actions.h:304
static TOOL_ACTION layerInner6
Definition: pcb_actions.h:296
static TOOL_ACTION layerInner22
Definition: pcb_actions.h:312
static TOOL_ACTION layerInner5
Definition: pcb_actions.h:295
static TOOL_ACTION layerInner20
Definition: pcb_actions.h:310
static TOOL_ACTION layerInner7
Definition: pcb_actions.h:297
static TOOL_ACTION layerInner27
Definition: pcb_actions.h:317
static TOOL_ACTION layerInner1
Definition: pcb_actions.h:291
static TOOL_ACTION layerInner10
Definition: pcb_actions.h:300
static TOOL_ACTION layerInner15
Definition: pcb_actions.h:305
static TOOL_ACTION layerInner17
Definition: pcb_actions.h:307
static TOOL_ACTION layerBottom
Definition: pcb_actions.h:321
static TOOL_ACTION layerInner19
Definition: pcb_actions.h:309
static TOOL_ACTION layerInner9
Definition: pcb_actions.h:299
static TOOL_ACTION layerInner30
Definition: pcb_actions.h:320
static TOOL_ACTION layerTop
Definition: pcb_actions.h:290
static TOOL_ACTION layerInner4
Definition: pcb_actions.h:294
static TOOL_ACTION layerInner13
Definition: pcb_actions.h:303
static TOOL_ACTION layerInner21
Definition: pcb_actions.h:311
static TOOL_ACTION layerInner23
Definition: pcb_actions.h:313
static TOOL_ACTION layerInner28
Definition: pcb_actions.h:318
BOARD * GetBoard() const
virtual COLOR_SETTINGS * GetColorSettings(bool aForceRefresh=false) const override
Helper to retrieve the current color settings.
COLOR4D getLayerColor(int aLayer) const override
bool isLayerEnabled(int aLayer) const override
wxString getLayerName(int aLayer) const override
T * GetAppSettings()
Returns a handle to the a given settings by type If the settings have already been loaded,...
COLOR_SETTINGS * GetColorSettings(const wxString &aName="user")
Retrieves a color settings object that applications can read colors from.
Represent a single user action.
Definition: tool_action.h:68
int GetHotKey() const
Return the hotkey keycode which initiates the action.
Definition: tool_action.h:111
#define _(s)
wxString AddHotkeyName(const wxString &aText, int aHotKey, HOTKEY_ACTION_TYPE aStyle)
@ IS_COMMENT
Definition: hotkeys_basic.h:78
@ LAYER_PCB_BACKGROUND
PCB background color.
Definition: layer_ids.h:220
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:59
@ In22_Cu
Definition: layer_ids.h:86
@ In11_Cu
Definition: layer_ids.h:75
@ In29_Cu
Definition: layer_ids.h:93
@ In30_Cu
Definition: layer_ids.h:94
@ In17_Cu
Definition: layer_ids.h:81
@ In9_Cu
Definition: layer_ids.h:73
@ In19_Cu
Definition: layer_ids.h:83
@ In7_Cu
Definition: layer_ids.h:71
@ In28_Cu
Definition: layer_ids.h:92
@ In26_Cu
Definition: layer_ids.h:90
@ B_Cu
Definition: layer_ids.h:95
@ In21_Cu
Definition: layer_ids.h:85
@ In23_Cu
Definition: layer_ids.h:87
@ In15_Cu
Definition: layer_ids.h:79
@ In2_Cu
Definition: layer_ids.h:66
@ In10_Cu
Definition: layer_ids.h:74
@ In4_Cu
Definition: layer_ids.h:68
@ UNDEFINED_LAYER
Definition: layer_ids.h:60
@ In16_Cu
Definition: layer_ids.h:80
@ In24_Cu
Definition: layer_ids.h:88
@ In1_Cu
Definition: layer_ids.h:65
@ In13_Cu
Definition: layer_ids.h:77
@ In8_Cu
Definition: layer_ids.h:72
@ In14_Cu
Definition: layer_ids.h:78
@ In12_Cu
Definition: layer_ids.h:76
@ In27_Cu
Definition: layer_ids.h:91
@ In6_Cu
Definition: layer_ids.h:70
@ In5_Cu
Definition: layer_ids.h:69
@ In3_Cu
Definition: layer_ids.h:67
@ In20_Cu
Definition: layer_ids.h:84
@ F_Cu
Definition: layer_ids.h:64
@ In18_Cu
Definition: layer_ids.h:82
@ In25_Cu
Definition: layer_ids.h:89
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:932
static TOOL_ACTION * layer2action(PCB_LAYER_ID aLayer)
see class PGM_BASE
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:115