KiCad PCB EDA Suite
gbr_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-2016 Jean-Pierre Charras <jp.charras at wanadoo.fr>
5 * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <[email protected]>
6 * Copyright (C) 1992-2021 KiCad Developers, see change_log.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 <gerbview_frame.h>
28
30
32{
33 #define BM_SIZE 14
34 Freeze();
35 Clear();
36
38
39 for( unsigned layerid = 0; layerid < images.ImagesMaxCount(); ++layerid )
40 {
41 if( !isLayerEnabled( layerid ) )
42 continue;
43
44 // Don't show unused layers
45 if ( images.GetGbrImage( layerid ) == nullptr )
46 continue;
47
48 // Prepare Bitmap
49 wxBitmap bmp( BM_SIZE, BM_SIZE );
51
52 Append( getLayerName( layerid ), bmp, (void*)(intptr_t) layerid );
53 }
54
55 // Ensure the size of the widget is enough to show the text and the icon
56 // We have to have a selected item when doing this, because otherwise GTK
57 // will just choose a random size that might not fit the actual data
58 // (such as in cases where the font size is very large). So we select
59 // the first item, get the size of the control and make that the minimum size,
60 // then remove the selection (which was the initial state).
61 if( GetCount() )
62 {
63 SetSelection( 0 );
64
65 SetMinSize( wxSize( -1, -1 ) );
66 wxSize bestSize = GetBestSize();
67
68 bestSize.x = GetBestSize().x + BM_SIZE + 10;
69 SetMinSize( bestSize );
70
71 SetSelection( wxNOT_FOUND );
72 }
73
74 Thaw();
75}
76
77
78// Returns a color index from the layer id
80{
81 GERBVIEW_FRAME* frame = (GERBVIEW_FRAME*) GetParent()->GetParent();
82
83 return frame->GetLayerColor( GERBER_DRAW_LAYER( aLayer ) );
84}
85
86
87// Returns the name of the layer id
88wxString GBR_LAYER_BOX_SELECTOR::getLayerName( int aLayer ) const
89{
91 wxString name = images.GetDisplayName( aLayer );
92
93 return name;
94}
const char * name
Definition: DXF_plotter.cpp:56
COLOR4D getLayerColor(int aLayer) const override
bool isLayerEnabled(int aLayer) const override
wxString getLayerName(int aLayer) const override
GERBER_FILE_IMAGE_LIST is a helper class to handle a list of GERBER_FILE_IMAGE files which are loaded...
static GERBER_FILE_IMAGE_LIST & GetImagesList()
const wxString GetDisplayName(int aIdx, bool aNameOnly=false, bool aFullName=false)
Get the display name for the layer at aIdx.
GERBER_FILE_IMAGE * GetGbrImage(int aIdx)
COLOR4D GetLayerColor(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)
#define BM_SIZE
@ LAYER_PCB_BACKGROUND
PCB background color.
Definition: layer_ids.h:220
#define GERBER_DRAW_LAYER(x)
Definition: layer_ids.h:423