KiCad PCB EDA Suite
class_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) 2014 Jean-Pierre Charras, jp.charras at wanadoo.fr
5  * Copyright (C) 2014 KiCad Developers, see CHANGELOG.TXT for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 #include <common.h>
26 #include <colors_selection.h>
28 #include <bitmaps.h>
29 
30 #include <wx/wx.h>
31 #include <wx/ownerdrw.h>
32 #include <wx/menuitem.h>
33 
35 
36 
38 {
39  m_layerhotkeys = true;
40  m_hotkeys = NULL;
41 }
42 
43 
45 {
46  m_layerhotkeys = value;
47  return m_layerhotkeys;
48 }
49 
50 
51 void LAYER_SELECTOR::SetBitmapLayer( wxBitmap& aLayerbmp, LAYER_NUM aLayer )
52 {
53  wxMemoryDC bmpDC;
54  wxBrush brush;
55 
56  // Prepare Bitmap
57  bmpDC.SelectObject( aLayerbmp );
58  brush.SetColour( GetLayerColor( aLayer ).ToColour() );
59  brush.SetStyle( wxBRUSHSTYLE_SOLID );
60 
61  bmpDC.SetBrush( brush );
62  bmpDC.DrawRectangle( 0, 0, aLayerbmp.GetWidth(), aLayerbmp.GetHeight() );
63  bmpDC.SetBrush( *wxTRANSPARENT_BRUSH );
64  bmpDC.SetPen( *wxBLACK_PEN );
65  bmpDC.DrawRectangle( 0, 0, aLayerbmp.GetWidth(), aLayerbmp.GetHeight() );
66 }
67 
68 /* class to display a layer list in a wxBitmapComboBox.
69  */
70 LAYER_BOX_SELECTOR::LAYER_BOX_SELECTOR( wxWindow* parent, wxWindowID id,
71  const wxPoint& pos, const wxSize& size,
72  int n, const wxString choices[] ) :
73  wxBitmapComboBox( parent, id, wxEmptyString, pos, size, n, choices, wxCB_READONLY ),
75 {
76  m_hotkeys = NULL;
77 
78  if( choices != NULL )
80 }
81 
82 
83 LAYER_BOX_SELECTOR::LAYER_BOX_SELECTOR( wxWindow* parent, wxWindowID id,
84  const wxPoint& pos, const wxSize& size,
85  const wxArrayString& choices ) :
86  wxBitmapComboBox( parent, id, wxEmptyString, pos, size, choices, wxCB_READONLY ),
88 {
89  m_hotkeys = NULL;
90 
91  if( !choices.IsEmpty() )
93 }
94 
95 
96 // Get Current Item #
98 {
99  return GetSelection();
100 }
101 
102 
103 // Get Current Layer
105 {
106  if( GetSelection() < 0 )
107  return UNDEFINED_LAYER;
108 
109  return (LAYER_NUM)(intptr_t) GetClientData( GetSelection() );
110 }
111 
112 
113 // Set Layer #
115 {
116  int elements = GetCount();
117 
118  for( int i = 0; i < elements; i++ )
119  {
120  if( GetClientData( i ) == (void*)(intptr_t) layer )
121  {
122  if( GetSelection() != i ) // Element (i) is not selected
123  {
124  SetSelection( i );
125  return i;
126  }
127  else
128  return i; //If element already selected; do nothing
129  }
130  }
131 
132  // Not Found
133  SetSelection( -1 );
134  return -1;
135 }
136 
137 
139 {
140  int elements = GetCount();
141 
142  for( LAYER_NUM i = 0; i < elements; ++i )
143  {
144  wxBitmap layerbmp( 14, 14 );
145  SetBitmapLayer( layerbmp, i );
146  }
147 }
148 
virtual COLOR4D GetLayerColor(LAYER_NUM aLayer) const =0
struct EDA_HOTKEY_CONFIG * m_hotkeys
LAYER_BOX_SELECTOR(wxWindow *parent, wxWindowID id, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, int n=0, const wxString choices[]=NULL)
void SetBitmapLayer(wxBitmap &aLayerbmp, LAYER_NUM aLayer)
int SetLayerSelection(LAYER_NUM layer)
struct EDA_HOTKEY_CONFIG * m_hotkeys
bool SetLayersHotkeys(bool value)
int LAYER_NUM
Type LAYER_NUM can be replaced with int and removed.
Board layer functions and definitions.
LAYER_NUM GetLayerSelection() const
The common library.