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
27
29
30#include <gerbview_frame.h>
32
33#ifdef __WXMSW__
34#include <dpi_scaling_common.h>
35#endif
36
37
42{
43public:
45
46 // Returns a color index from the layer id
47 COLOR4D getLayerColor( int aLayer ) const override
48 {
49 return m_frame.GetLayerColor( GERBER_DRAW_LAYER( aLayer ) );
50 }
51
52 // Returns the name of the layer id
53 wxString getLayerName( int aLayer ) const override
54 {
56 wxString name = images.GetDisplayName( aLayer );
57
58 return name;
59 }
60
61private:
63};
64
65
66GBR_LAYER_BOX_SELECTOR::GBR_LAYER_BOX_SELECTOR( wxWindow* parent, wxWindowID id, const wxPoint& pos,
67 const wxSize& size, int n,
68 const wxString choices[] ) :
69 LAYER_BOX_SELECTOR( parent, id, pos, size, n, choices ),
70 m_layerPresentation( std::make_unique<GBR_LAYER_PRESENTATION>(
71 static_cast<GERBVIEW_FRAME&>( *parent->GetParent() ) ) )
72{
73 m_layerhotkeys = false;
74}
75
77{
78 Freeze();
79 Clear();
80
81 const int size = 14;
82
84
85 for( unsigned layerid = 0; layerid < images.ImagesMaxCount(); ++layerid )
86 {
87 if( !isLayerEnabled( layerid ) )
88 continue;
89
90 // Don't show unused layers
91 if ( images.GetGbrImage( layerid ) == nullptr )
92 continue;
93
94 // Prepare Bitmaps
95 wxVector<wxBitmap> bitmaps;
96
97 for( int scale = 1; scale <= 3; scale++ )
98 {
99 wxBitmap bmp( size * scale, size * scale );
100
101 m_layerPresentation->DrawColorSwatch( bmp, layerid );
102
103 bmp.SetScaleFactor( scale );
104 bitmaps.push_back( bmp );
105 }
106
107 Append( m_layerPresentation->getLayerName( layerid ),
108 wxBitmapBundle::FromBitmaps( bitmaps ), (void*) (intptr_t) layerid );
109 }
110
111 // Ensure the size of the widget is enough to show the text and the icon
112 // We have to have a selected item when doing this, because otherwise GTK
113 // will just choose a random size that might not fit the actual data
114 // (such as in cases where the font size is very large). So we select
115 // the first item, get the size of the control and make that the minimum size,
116 // then remove the selection (which was the initial state).
117 if( GetCount() )
118 {
119 SetSelection( 0 );
120
121 SetMinSize( wxSize( -1, -1 ) );
122 wxSize bestSize = GetBestSize();
123
124 bestSize.x = GetBestSize().x + size + 10;
125 SetMinSize( bestSize );
126
127 SetSelection( wxNOT_FOUND );
128 }
129
130 Thaw();
131}
const char * name
Definition: DXF_plotter.cpp:57
std::unique_ptr< LAYER_PRESENTATION > m_layerPresentation
bool isLayerEnabled(int aLayer) const override
GBR_LAYER_BOX_SELECTOR(wxWindow *parent, wxWindowID id, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, int n=0, const wxString choices[]=nullptr)
Gerbview-specific implementation of the LAYER_PRESENTATION interface.
GBR_LAYER_PRESENTATION(GERBVIEW_FRAME &aFrame)
COLOR4D getLayerColor(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
Base class for an object that can provide information about presenting layers (colours,...
#define GERBER_DRAW_LAYER(x)
Definition: layer_ids.h:442
STL namespace.
const int scale