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>
27 #include <bitmaps.h>
28 
29 #include <wx/wx.h>
30 #include <wx/ownerdrw.h>
31 #include <wx/menuitem.h>
32 
34 
35 
37 {
38  m_layerhotkeys = true;
39  m_hotkeys = NULL;
40 }
41 
42 
44 {
45  m_layerhotkeys = value;
46  return m_layerhotkeys;
47 }
48 
49 
50 void LAYER_SELECTOR::SetBitmapLayer( wxBitmap& aLayerbmp, LAYER_NUM aLayer )
51 {
52  wxMemoryDC bmpDC;
53  wxBrush brush;
54 
55  // Prepare Bitmap
56  bmpDC.SelectObject( aLayerbmp );
57  brush.SetColour( GetLayerColor( aLayer ).ToColour() );
58  brush.SetStyle( wxBRUSHSTYLE_SOLID );
59 
60  bmpDC.SetBrush( brush );
61  bmpDC.DrawRectangle( 0, 0, aLayerbmp.GetWidth(), aLayerbmp.GetHeight() );
62  bmpDC.SetBrush( *wxTRANSPARENT_BRUSH );
63  bmpDC.SetPen( *wxBLACK_PEN );
64  bmpDC.DrawRectangle( 0, 0, aLayerbmp.GetWidth(), aLayerbmp.GetHeight() );
65 }
66 
67 /* class to display a layer list in a wxBitmapComboBox.
68  */
69 LAYER_BOX_SELECTOR::LAYER_BOX_SELECTOR( wxWindow* parent, wxWindowID id,
70  const wxPoint& pos, const wxSize& size,
71  int n, const wxString choices[] ) :
72  wxBitmapComboBox( parent, id, wxEmptyString, pos, size, n, choices, wxCB_READONLY ),
74 {
75  m_hotkeys = NULL;
76 
77  if( choices != NULL )
79 }
80 
81 
82 LAYER_BOX_SELECTOR::LAYER_BOX_SELECTOR( wxWindow* parent, wxWindowID id,
83  const wxPoint& pos, const wxSize& size,
84  const wxArrayString& choices ) :
85  wxBitmapComboBox( parent, id, wxEmptyString, pos, size, choices, wxCB_READONLY ),
87 {
88  m_hotkeys = NULL;
89 
90  if( !choices.IsEmpty() )
92 }
93 
94 
95 // Get Current Item #
97 {
98  return GetSelection();
99 }
100 
101 
102 // Get Current Layer
104 {
105  if( GetSelection() < 0 )
106  return UNDEFINED_LAYER;
107 
108  return (LAYER_NUM)(intptr_t) GetClientData( GetSelection() );
109 }
110 
111 
112 // Set Layer #
114 {
115  int elements = GetCount();
116 
117  for( int i = 0; i < elements; i++ )
118  {
119  if( GetClientData( i ) == (void*)(intptr_t) layer )
120  {
121  if( GetSelection() != i ) // Element (i) is not selected
122  {
123  SetSelection( i );
124  return i;
125  }
126  else
127  return i; //If element already selected; do nothing
128  }
129  }
130 
131  // Not Found
132  SetSelection( -1 );
133  return -1;
134 }
135 
136 
138 {
139  int elements = GetCount();
140 
141  for( LAYER_NUM i = 0; i < elements; ++i )
142  {
143  wxBitmap layerbmp( 14, 14 );
144  SetBitmapLayer( layerbmp, i );
145  }
146 }
147 
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.