KiCad PCB EDA Suite
PCB_LAYER_BOX_SELECTOR Class Reference

Class to display a pcb layer list in a wxBitmapComboBox. More...

#include <pcb_layer_box_selector.h>

Inheritance diagram for PCB_LAYER_BOX_SELECTOR:
LAYER_BOX_SELECTOR LAYER_SELECTOR

Public Member Functions

 PCB_LAYER_BOX_SELECTOR (wxWindow *parent, wxWindowID id, const wxString &value=wxEmptyString, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, int n=0, const wxString choices[]=NULL, int style=0)
 
void SetBoardFrame (PCB_BASE_FRAME *aFrame)
 
void SetNotAllowedLayerSet (LSET aMask)
 
void Resync () override
 
void ShowNonActivatedLayers (bool aShow)
 
int GetChoice ()
 
LAYER_NUM GetLayerSelection () const
 
int SetLayerSelection (LAYER_NUM layer)
 
void ResyncBitmapOnly ()
 
bool SetLayersHotkeys (bool value)
 

Static Public Member Functions

static void DrawColorSwatch (wxBitmap &aLayerbmp, COLOR4D aBackground, COLOR4D aColor)
 

Public Attributes

EDA_HOTKEY_CONFIGm_hotkeys
 

Protected Attributes

bool m_layerhotkeys
 

Private Member Functions

COLOR4D GetLayerColor (LAYER_NUM aLayer) const override
 
bool IsLayerEnabled (LAYER_NUM aLayer) const override
 
wxString GetLayerName (LAYER_NUM aLayer) const override
 
LSET getEnabledLayers () const
 

Private Attributes

PCB_BASE_FRAMEm_boardFrame
 
LSET m_layerMaskDisable
 
bool m_showNotEnabledBrdlayers
 

Detailed Description

Class to display a pcb layer list in a wxBitmapComboBox.

Definition at line 35 of file pcb_layer_box_selector.h.

Constructor & Destructor Documentation

PCB_LAYER_BOX_SELECTOR::PCB_LAYER_BOX_SELECTOR ( wxWindow *  parent,
wxWindowID  id,
const wxString &  value = wxEmptyString,
const wxPoint pos = wxDefaultPosition,
const wxSize &  size = wxDefaultSize,
int  n = 0,
const wxString  choices[] = NULL,
int  style = 0 
)
inline

Definition at line 54 of file pcb_layer_box_selector.h.

58  :
59  LAYER_BOX_SELECTOR( parent, id, pos, size, n, choices )
60  {
61  m_boardFrame = NULL;
62  m_hotkeys = NULL;
64  }
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)

Member Function Documentation

void LAYER_SELECTOR::DrawColorSwatch ( wxBitmap &  aLayerbmp,
COLOR4D  aBackground,
COLOR4D  aColor 
)
staticinherited

Definition at line 48 of file layer_box_selector.cpp.

References KIGFX::COLOR4D::WithAlpha().

Referenced by GRID_CELL_LAYER_RENDERER::Draw(), GBR_LAYER_BOX_SELECTOR::Resync(), Resync(), and LAYER_BOX_SELECTOR::ResyncBitmapOnly().

49 {
50  wxMemoryDC bmpDC;
51  wxBrush brush;
52 
53  // Prepare Bitmap
54  bmpDC.SelectObject( aLayerbmp );
55 
56  brush.SetStyle( wxBRUSHSTYLE_SOLID );
57  if( aBackground != COLOR4D::UNSPECIFIED )
58  {
59  brush.SetColour( aBackground.WithAlpha(1.0).ToColour() );
60  bmpDC.SetBrush( brush );
61  bmpDC.DrawRectangle( 0, 0, aLayerbmp.GetWidth(), aLayerbmp.GetHeight() );
62  }
63 
64  brush.SetColour( aColor.ToColour() );
65  bmpDC.SetBrush( brush );
66  bmpDC.DrawRectangle( 0, 0, aLayerbmp.GetWidth(), aLayerbmp.GetHeight() );
67 
68  bmpDC.SetBrush( *wxTRANSPARENT_BRUSH );
69  bmpDC.SetPen( *wxBLACK_PEN );
70  bmpDC.DrawRectangle( 0, 0, aLayerbmp.GetWidth(), aLayerbmp.GetHeight() );
71 }
COLOR4D WithAlpha(double aAlpha) const
Function WithAlpha Returns a colour with the same colour, but the given alpha.
Definition: color4d.h:233
int LAYER_BOX_SELECTOR::GetChoice ( )
inherited

Definition at line 114 of file layer_box_selector.cpp.

115 {
116  return GetSelection();
117 }
LSET PCB_LAYER_BOX_SELECTOR::getEnabledLayers ( ) const
private

Definition at line 138 of file pcb_layer_box_selector.cpp.

References PCB_BASE_FRAME::GetBoard(), BOARD::GetEnabledLayers(), and m_boardFrame.

Referenced by Resync(), and ShowNonActivatedLayers().

139 {
140  wxASSERT( m_boardFrame != NULL );
141  BOARD* board = m_boardFrame->GetBoard();
142  wxASSERT( board != NULL );
143 
144  return board->GetEnabledLayers();
145 }
BOARD * GetBoard() const
LSET GetEnabledLayers() const
Function GetEnabledLayers is a proxy function that calls the corresponding function in m_BoardSetting...
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:170
COLOR4D PCB_LAYER_BOX_SELECTOR::GetLayerColor ( LAYER_NUM  aLayer) const
overrideprivatevirtual

Implements LAYER_SELECTOR.

Definition at line 149 of file pcb_layer_box_selector.cpp.

References PCB_GENERAL_SETTINGS::Colors(), COLORS_DESIGN_SETTINGS::GetLayerColor(), m_boardFrame, and PCB_BASE_FRAME::Settings().

Referenced by Resync(), and ShowNonActivatedLayers().

150 {
151  wxASSERT( m_boardFrame );
152 
153  return m_boardFrame->Settings().Colors().GetLayerColor( aLayer );
154 }
PCB_GENERAL_SETTINGS & Settings()
COLORS_DESIGN_SETTINGS & Colors()
COLOR4D GetLayerColor(LAYER_NUM aLayer) const
Function GetLayerColor.
wxString PCB_LAYER_BOX_SELECTOR::GetLayerName ( LAYER_NUM  aLayer) const
overrideprivatevirtual

Implements LAYER_SELECTOR.

Definition at line 158 of file pcb_layer_box_selector.cpp.

References PCB_BASE_FRAME::GetBoard(), BOARD::GetLayerName(), m_boardFrame, and ToLAYER_ID().

Referenced by Resync(), and ShowNonActivatedLayers().

159 {
160  wxASSERT( m_boardFrame );
161  BOARD* board = m_boardFrame->GetBoard();
162  wxASSERT( board );
163 
164  return board->GetLayerName( ToLAYER_ID( aLayer ) );
165 }
BOARD * GetBoard() const
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Function GetLayerName returns the name of a layer given by aLayer.
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:170
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:810
bool PCB_LAYER_BOX_SELECTOR::IsLayerEnabled ( LAYER_NUM  aLayer) const
overrideprivatevirtual

Implements LAYER_SELECTOR.

Definition at line 128 of file pcb_layer_box_selector.cpp.

References PCB_BASE_FRAME::GetBoard(), BOARD::IsLayerEnabled(), m_boardFrame, and ToLAYER_ID().

Referenced by ShowNonActivatedLayers().

129 {
130  wxASSERT( m_boardFrame != NULL );
131  BOARD* board = m_boardFrame->GetBoard();
132  wxASSERT( board != NULL );
133 
134  return board->IsLayerEnabled( ToLAYER_ID( aLayer ) );
135 }
bool IsLayerEnabled(PCB_LAYER_ID aLayer) const
Function IsLayerEnabled is a proxy function that calls the correspondent function in m_BoardSettings ...
Definition: class_board.h:445
BOARD * GetBoard() const
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:170
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:810
void PCB_LAYER_BOX_SELECTOR::Resync ( )
overridevirtual

Implements LAYER_BOX_SELECTOR.

Definition at line 75 of file pcb_layer_box_selector.cpp.

References AddHotkeyName(), LSET::AllLayersMask(), BM_SIZE, LAYER_SELECTOR::DrawColorSwatch(), getEnabledLayers(), GetLayerColor(), GetLayerName(), IS_COMMENT, layer2hotkey_id(), LAYER_PCB_BACKGROUND, m_hotkeys, LAYER_SELECTOR::m_layerhotkeys, m_layerMaskDisable, m_showNotEnabledBrdlayers, max, and LSET::UIOrder().

Referenced by GRID_CELL_LAYER_SELECTOR::BeginEdit(), DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS::buildFilterLists(), DIALOG_DXF_IMPORT::DIALOG_DXF_IMPORT(), DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS::DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS(), DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS::DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS(), DIALOG_GRAPHIC_ITEM_PROPERTIES::DIALOG_GRAPHIC_ITEM_PROPERTIES(), DIALOG_TEXT_PROPERTIES::DIALOG_TEXT_PROPERTIES(), DIALOG_TRACK_VIA_PROPERTIES::DIALOG_TRACK_VIA_PROPERTIES(), PCB_EDIT_FRAME::ReCreateLayerBox(), and SetNotAllowedLayerSet().

76 {
77  Clear();
78 
79  // Tray to fix a minimum width fot the BitmapComboBox
80  int minwidth = 80;
81 
82  wxClientDC dc( GetParent() ); // The DC for "this" is not always initialized
83 
84  const int BM_SIZE = 14;
85 
87  LSET activated = getEnabledLayers() & ~m_layerMaskDisable;
88  wxString layerstatus;
89 
90  for( LSEQ seq = show.UIOrder(); seq; ++seq )
91  {
92  PCB_LAYER_ID layerid = *seq;
93 
94  if( !m_showNotEnabledBrdlayers && !activated[layerid] )
95  continue;
96  else if( !activated[layerid] )
97  layerstatus = wxT( " " ) + _( "(not activated)" );
98  else
99  layerstatus.Empty();
100 
101  wxBitmap bmp( BM_SIZE, BM_SIZE );
103 
104  wxString layername = GetLayerName( layerid ) + layerstatus;
105 
106  if( m_layerhotkeys && m_hotkeys )
107  {
108  int id = layer2hotkey_id( layerid );
109 
110  if( id != -1 )
111  layername = AddHotkeyName( layername, m_hotkeys, id, IS_COMMENT );
112  }
113 
114  Append( layername, bmp, (void*)(intptr_t) layerid );
115 
116  int w, h;
117  dc.GetTextExtent ( layername, &w, &h );
118  minwidth = std::max( minwidth, w );
119  }
120 
121  // Approximate bitmap size and margins
122  minwidth += BM_SIZE + 32 + ConvertDialogToPixels( wxSize( 8, 0 ) ).x;
123  SetMinSize( wxSize( minwidth, -1 ) );
124 }
EDA_HOTKEY_CONFIG * m_hotkeys
PCB_LAYER_ID
A quick note on layer IDs:
Class LSET is a set of PCB_LAYER_IDs.
static LSET AllLayersMask()
Definition: lset.cpp:710
Class LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
static int layer2hotkey_id(PCB_LAYER_ID aLayer)
static void DrawColorSwatch(wxBitmap &aLayerbmp, COLOR4D aBackground, COLOR4D aColor)
#define BM_SIZE
wxString AddHotkeyName(const wxString &aText, EDA_HOTKEY **aList, int aCommandId, HOTKEY_ACTION_TYPE aShortCutType)
Function AddHotkeyName Add the key name from the Command id value ( m_Idcommand member value) ...
#define max(a, b)
Definition: auxiliary.h:86
COLOR4D GetLayerColor(LAYER_NUM aLayer) const override
wxString GetLayerName(LAYER_NUM aLayer) const override
LSEQ UIOrder() const
Definition: lset.cpp:800
void LAYER_BOX_SELECTOR::ResyncBitmapOnly ( )
inherited

Definition at line 155 of file layer_box_selector.cpp.

References LAYER_SELECTOR::DrawColorSwatch(), LAYER_SELECTOR::GetLayerColor(), i, and LAYER_PCB_BACKGROUND.

Referenced by LAYER_BOX_SELECTOR::LAYER_BOX_SELECTOR(), and GERBER_LAYER_WIDGET::OnLayerColorChange().

156 {
157  int elements = GetCount();
158 
159  for( LAYER_NUM i = 0; i < elements; ++i )
160  {
161  wxBitmap layerbmp( 14, 14 );
163  }
164 }
virtual COLOR4D GetLayerColor(LAYER_NUM aLayer) const =0
int LAYER_NUM
Type LAYER_NUM can be replaced with int and removed.
static void DrawColorSwatch(wxBitmap &aLayerbmp, COLOR4D aBackground, COLOR4D aColor)
size_t i
Definition: json11.cpp:597
int LAYER_BOX_SELECTOR::SetLayerSelection ( LAYER_NUM  layer)
inherited

Definition at line 131 of file layer_box_selector.cpp.

References i.

Referenced by GRID_CELL_LAYER_SELECTOR::BeginEdit(), DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS::buildFilterLists(), DIALOG_DXF_IMPORT::DIALOG_DXF_IMPORT(), DIALOG_TRACK_VIA_PROPERTIES::DIALOG_TRACK_VIA_PROPERTIES(), PCB_EDIT_FRAME::OnUpdateLayerSelectBox(), DIALOG_TRACK_VIA_PROPERTIES::onViaEdit(), GRID_CELL_LAYER_SELECTOR::Reset(), DIALOG_TEXT_PROPERTIES::TransferDataToWindow(), DIALOG_GRAPHIC_ITEM_PROPERTIES::TransferDataToWindow(), DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS::TransferDataToWindow(), and DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS::TransferDataToWindow().

132 {
133  int elements = GetCount();
134 
135  for( int i = 0; i < elements; i++ )
136  {
137  if( GetClientData( (unsigned) i ) == (void*)(intptr_t) layer )
138  {
139  if( GetSelection() != i ) // Element (i) is not selected
140  {
141  SetSelection( i );
142  return i;
143  }
144  else
145  return i; //If element already selected; do nothing
146  }
147  }
148 
149  // Not Found
150  SetSelection( -1 );
151  return -1;
152 }
size_t i
Definition: json11.cpp:597
void PCB_LAYER_BOX_SELECTOR::ShowNonActivatedLayers ( bool  aShow)
inline

Member Data Documentation

PCB_BASE_FRAME* PCB_LAYER_BOX_SELECTOR::m_boardFrame
private
EDA_HOTKEY_CONFIG* PCB_LAYER_BOX_SELECTOR::m_hotkeys

Definition at line 46 of file pcb_layer_box_selector.h.

Referenced by PCB_EDIT_FRAME::ReCreateLayerBox(), and Resync().

bool LAYER_SELECTOR::m_layerhotkeys
protectedinherited
LSET PCB_LAYER_BOX_SELECTOR::m_layerMaskDisable
private

Definition at line 39 of file pcb_layer_box_selector.h.

Referenced by Resync().

bool PCB_LAYER_BOX_SELECTOR::m_showNotEnabledBrdlayers
private

Definition at line 41 of file pcb_layer_box_selector.h.

Referenced by Resync().


The documentation for this class was generated from the following files: