KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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-2024 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
29#ifdef __WXMSW__
30#include <dpi_scaling_common.h>
31#endif
32
34
36{
37 Freeze();
38 Clear();
39
40 const int size = 14;
41
43
44 for( unsigned layerid = 0; layerid < images.ImagesMaxCount(); ++layerid )
45 {
46 if( !isLayerEnabled( layerid ) )
47 continue;
48
49 // Don't show unused layers
50 if ( images.GetGbrImage( layerid ) == nullptr )
51 continue;
52
53 // Prepare Bitmaps
54 wxVector<wxBitmap> bitmaps;
55
56 for( int scale = 1; scale <= 3; scale++ )
57 {
58 wxBitmap bmp( size * scale, size * scale );
59
61
62 bmp.SetScaleFactor( scale );
63 bitmaps.push_back( bmp );
64 }
65
66 Append( getLayerName( layerid ), wxBitmapBundle::FromBitmaps( bitmaps ),
67 (void*) (intptr_t) layerid );
68 }
69
70 // Ensure the size of the widget is enough to show the text and the icon
71 // We have to have a selected item when doing this, because otherwise GTK
72 // will just choose a random size that might not fit the actual data
73 // (such as in cases where the font size is very large). So we select
74 // the first item, get the size of the control and make that the minimum size,
75 // then remove the selection (which was the initial state).
76 if( GetCount() )
77 {
78 SetSelection( 0 );
79
80 SetMinSize( wxSize( -1, -1 ) );
81 wxSize bestSize = GetBestSize();
82
83 bestSize.x = GetBestSize().x + size + 10;
84 SetMinSize( bestSize );
85
86 SetSelection( wxNOT_FOUND );
87 }
88
89 Thaw();
90}
91
92
93// Returns a color index from the layer id
95{
96 GERBVIEW_FRAME* frame = (GERBVIEW_FRAME*) GetParent()->GetParent();
97
98 return frame->GetLayerColor( GERBER_DRAW_LAYER( aLayer ) );
99}
100
101
102// Returns the name of the layer id
103wxString GBR_LAYER_BOX_SELECTOR::getLayerName( int aLayer ) const
104{
106 wxString name = images.GetDisplayName( aLayer );
107
108 return name;
109}
const char * name
Definition: DXF_plotter.cpp:57
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)
@ LAYER_PCB_BACKGROUND
PCB background color.
Definition: layer_ids.h:224
#define GERBER_DRAW_LAYER(x)
Definition: layer_ids.h:441
const int scale