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 The 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
27
28#include <board.h>
29#include <layer_ids.h>
30#include <pcb_edit_frame.h>
33#include <tools/pcb_actions.h>
34#include <dpi_scaling_common.h>
35#include <wx/wupdlock.h>
36
37
38PCB_LAYER_BOX_SELECTOR::PCB_LAYER_BOX_SELECTOR( wxWindow* parent, wxWindowID id, const wxString& value,
39 const wxPoint& pos, const wxSize& size, int n,
40 const wxString choices[], int style ) :
41 LAYER_BOX_SELECTOR( parent, id, pos, size, n, choices ),
42 m_boardFrame( nullptr ),
43 m_showNotEnabledBrdlayers( false ),
44 m_layerPresentation( std::make_unique<PCB_LAYER_PRESENTATION>( nullptr ) ) // The parent isn't always the frame
45{
46}
47
48
50{
51 m_boardFrame = aFrame;
52 m_layerPresentation->SetBoardFrame( m_boardFrame );
53}
54
55
56// Reload the Layers
58{
59 wxWindowUpdateLocker updateLock( this );
60
61 Clear();
62
63 const int size = 14;
64
66 LSET activated = getEnabledLayers() & ~m_layerMaskDisable;
67 wxString layerstatus;
68
69 for( PCB_LAYER_ID layerid : show.UIOrder() )
70 {
71 if( !m_showNotEnabledBrdlayers && !activated[layerid] )
72 continue;
73 else if( !activated[layerid] )
74 layerstatus = wxT( " " ) + _( "(not activated)" );
75 else
76 layerstatus.Empty();
77
78 wxVector<wxBitmap> bitmaps;
79
80 for( int scale = 1; scale <= 3; scale++ )
81 {
82 wxBitmap bmp( size * scale, size * scale );
83
84 m_layerPresentation->DrawColorSwatch( bmp, layerid );
85
86 bmp.SetScaleFactor( scale );
87 bitmaps.push_back( bmp );
88 }
89
90 wxString layername = m_layerPresentation->getLayerName( layerid ) + layerstatus;
91
92 if( m_layerhotkeys )
93 {
94 TOOL_ACTION* action = PCB_ACTIONS::LayerIDToAction( layerid );
95
96 if( action )
97 layername = AddHotkeyName( layername, action->GetHotKey(), IS_COMMENT );
98 }
99
100 Append( layername, wxBitmapBundle::FromBitmaps( bitmaps ), (void*) (intptr_t) layerid );
101 }
102
103 if( !m_undefinedLayerName.IsEmpty() )
104 Append( m_undefinedLayerName, wxNullBitmap, (void*)(intptr_t)UNDEFINED_LAYER );
105
106 // Ensure the size of the widget is enough to show the text and the icon
107 // We have to have a selected item when doing this, because otherwise GTK
108 // will just choose a random size that might not fit the actual data
109 // (such as in cases where the font size is very large). So we select
110 // the first item, get the size of the control and make that the minimum size,
111 // then remove the selection (which was the initial state).
112 SetSelection( 0 );
113
114 SetMinSize( wxSize( -1, -1 ) );
115 wxSize bestSize = GetBestSize();
116
117 bestSize.x = GetBestSize().x + size + 10;
118 SetMinSize( bestSize );
119
120 SetSelection( wxNOT_FOUND );
121 Fit();
122}
123
124
125// Returns true if the layer id is enabled (i.e. is it should be displayed)
127{
128 return getEnabledLayers().test( aLayer );
129}
130
131
133{
134 static LSET footprintEditorLayers = LSET::AllLayersMask() & ~LSET::ForbiddenFootprintLayers();
135
136 if( m_boardFrame )
138 else
139 return footprintEditorLayers;
140}
const LSET & GetEnabledLayers() const
A proxy function that calls the corresponding function in m_BoardSettings.
Definition: board.cpp:907
Display a layer list in a wxBitmapComboBox.
LSET is a set of PCB_LAYER_IDs.
Definition: lset.h:37
LSEQ UIOrder() const
Return the copper, technical and user layers in the order shown in layer widget.
Definition: lset.cpp:733
static LSET AllNonCuMask()
Return a mask holding all layer minus CU layers.
Definition: lset.cpp:610
static const LSET & AllLayersMask()
Definition: lset.cpp:624
static LSET AllCuMask()
return AllCuMask( MAX_CU_LAYERS );
Definition: lset.cpp:591
static TOOL_ACTION * LayerIDToAction(PCB_LAYER_ID aLayerID)
Translate a layer ID into the action that switches to that layer.
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
BOARD * GetBoard() const
void SetBoardFrame(PCB_BASE_FRAME *aFrame)
bool isLayerEnabled(int aLayer) const override
Return true if the layer id is enabled (i.e. is it should be displayed).
PCB_LAYER_BOX_SELECTOR(wxWindow *parent, wxWindowID id, const wxString &value=wxEmptyString, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, int n=0, const wxString choices[]=nullptr, int style=0)
std::unique_ptr< PCB_LAYER_PRESENTATION > m_layerPresentation
Class that manages the presentation of PCB layers in a PCB frame.
Represent a single user action.
Definition: tool_action.h:304
int GetHotKey() const
Return the hotkey keycode which initiates the action.
Definition: tool_action.h:348
#define _(s)
wxString AddHotkeyName(const wxString &aText, int aHotKey, HOTKEY_ACTION_TYPE aStyle)
@ IS_COMMENT
Definition: hotkeys_basic.h:82
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:60
@ UNDEFINED_LAYER
Definition: layer_ids.h:61
STL namespace.
const int scale