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