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 <dick@softplc.com>
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>
27 #include <gerber_file_image_list.h>
28 
29 #include "gbr_layer_box_selector.h"
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  // Prepare Bitmap
45  wxBitmap bmp( BM_SIZE, BM_SIZE );
47 
48  Append( getLayerName( layerid ), bmp, (void*)(intptr_t) layerid );
49  }
50 
51  // Ensure the size of the widget is enough to show the text and the icon
52  // We have to have a selected item when doing this, because otherwise GTK
53  // will just choose a random size that might not fit the actual data
54  // (such as in cases where the font size is very large). So we select
55  // the first item, get the size of the control and make that the minimum size,
56  // then remove the selection (which was the initial state).
57  SetSelection( 0 );
58 
59  SetMinSize( wxSize( -1, -1 ) );
60  wxSize bestSize = GetBestSize();
61 
62  bestSize.x = GetBestSize().x + BM_SIZE + 10;
63  SetMinSize( bestSize );
64 
65  SetSelection( wxNOT_FOUND );
66  Thaw();
67 }
68 
69 
70 // Returns a color index from the layer id
72 {
73  GERBVIEW_FRAME* frame = (GERBVIEW_FRAME*) GetParent()->GetParent();
74 
75  return frame->GetLayerColor( GERBER_DRAW_LAYER( aLayer ) );
76 }
77 
78 
79 // Returns the name of the layer id
80 wxString GBR_LAYER_BOX_SELECTOR::getLayerName( int aLayer ) const
81 {
83  wxString name = images.GetDisplayName( aLayer );
84 
85  return name;
86 }
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()
wxString getLayerName(int aLayer) const override
static void DrawColorSwatch(wxBitmap &aLayerbmp, COLOR4D aBackground, COLOR4D aColor)
#define BM_SIZE
const char * name
Definition: DXF_plotter.cpp:59
COLOR4D GetLayerColor(int aLayer) const
COLOR4D getLayerColor(int aLayer) const override
#define GERBER_DRAW_LAYER(x)
const wxString GetDisplayName(int aIdx, bool aNameOnly=false, bool aFullName=false)
Get the display name for the layer at aIdx.
bool isLayerEnabled(int aLayer) const override
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:98