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-2024 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#include <dpi_scaling_common.h>
36
37
38// class to display a layer list in a wxBitmapComboBox.
39
40// Reload the Layers
42{
43 Freeze();
44 Clear();
45
46 const int size = 14;
47
48 LSET show = LSET::AllLayersMask() & ~m_layerMaskDisable;
49 LSET activated = getEnabledLayers() & ~m_layerMaskDisable;
50 wxString layerstatus;
51
52 for( PCB_LAYER_ID layerid : show.UIOrder() )
53 {
54 if( !m_showNotEnabledBrdlayers && !activated[layerid] )
55 continue;
56 else if( !activated[layerid] )
57 layerstatus = wxT( " " ) + _( "(not activated)" );
58 else
59 layerstatus.Empty();
60
61 wxVector<wxBitmap> bitmaps;
62
63 for( int scale = 1; scale <= 3; scale++ )
64 {
65 wxBitmap bmp( size * scale, size * scale );
66
68
69 bmp.SetScaleFactor( scale );
70 bitmaps.push_back( bmp );
71 }
72
73 wxString layername = getLayerName( layerid ) + layerstatus;
74
75 if( m_layerhotkeys )
76 {
77 TOOL_ACTION* action = PCB_ACTIONS::LayerIDToAction( layerid );
78
79 if( action )
80 layername = AddHotkeyName( layername, action->GetHotKey(), IS_COMMENT );
81 }
82
83 Append( layername, wxBitmapBundle::FromBitmaps( bitmaps ), (void*) (intptr_t) layerid );
84 }
85
86 if( !m_undefinedLayerName.IsEmpty() )
87 Append( m_undefinedLayerName, wxNullBitmap, (void*)(intptr_t)UNDEFINED_LAYER );
88
89 // Ensure the size of the widget is enough to show the text and the icon
90 // We have to have a selected item when doing this, because otherwise GTK
91 // will just choose a random size that might not fit the actual data
92 // (such as in cases where the font size is very large). So we select
93 // the first item, get the size of the control and make that the minimum size,
94 // then remove the selection (which was the initial state).
95 SetSelection( 0 );
96
97 SetMinSize( wxSize( -1, -1 ) );
98 wxSize bestSize = GetBestSize();
99
100 bestSize.x = GetBestSize().x + size + 10;
101 SetMinSize( bestSize );
102
103 SetSelection( wxNOT_FOUND );
104 Fit();
105 Thaw();
106}
107
108
109// Returns true if the layer id is enabled (i.e. is it should be displayed)
111{
112 return getEnabledLayers().test( aLayer );
113}
114
115
117{
118 static LSET footprintEditorLayers = LSET::AllLayersMask() & ~LSET::ForbiddenFootprintLayers();
119
120 if( m_boardFrame )
122 else
123 return footprintEditorLayers;
124}
125
126
127// Returns a color index from the layer id
129{
130 if( m_boardFrame )
131 {
132 return m_boardFrame->GetColorSettings()->GetColor( aLayer );
133 }
134 else
135 {
138 COLOR_SETTINGS* current = mgr.GetColorSettings( settings->m_ColorTheme );
139
140 return current->GetColor( aLayer );
141 }
142}
143
144
145// Returns the name of the layer id
146wxString PCB_LAYER_BOX_SELECTOR::getLayerName( int aLayer ) const
147{
148 if( m_boardFrame )
149 return m_boardFrame->GetBoard()->GetLayerName( ToLAYER_ID( aLayer ) );
150 else
151 return BOARD::GetStandardLayerName( ToLAYER_ID( aLayer ) );
152}
wxString m_ColorTheme
Active color theme name.
Definition: app_settings.h:175
bool test(size_t pos) const
Definition: base_set.h:47
LSET GetEnabledLayers() const
A proxy function that calls the corresponding function in m_BoardSettings.
Definition: board.cpp:757
static wxString GetStandardLayerName(PCB_LAYER_ID aLayerId)
Return an "English Standard" name of a PCB layer when given aLayerNumber.
Definition: board.h:779
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Return the name of a aLayer.
Definition: board.cpp:575
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
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
static void DrawColorSwatch(wxBitmap &aLayerbmp, const COLOR4D &aBackground, const COLOR4D &aColor)
LSET is a set of PCB_LAYER_IDs.
Definition: lset.h:35
LSEQ UIOrder() const
Definition: lset.cpp:865
static LSET AllLayersMask()
Definition: lset.cpp:767
static TOOL_ACTION * LayerIDToAction(PCB_LAYER_ID aLayerID)
Translate a layer ID into the action that switches to that layer.
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
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:142
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:269
int GetHotKey() const
Return the hotkey keycode which initiates the action.
Definition: tool_action.h:313
#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:224
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:60
@ UNDEFINED_LAYER
Definition: layer_ids.h:61
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:875
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: pgm_base.cpp:1059
see class PGM_BASE
const int scale